summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/browserElement_ThemeColor.js
blob: 01e9c5c36451a5c7346244422fc1043a9e6a8fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Any copyright is dedicated to the public domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that the onmozbrowsermetachange event for theme-color works.
"use strict";

SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();

function runTest() {
  function loadFrameScript(script) {
    SpecialPowers.getBrowserFrameMessageManager(iframe1)
                 .loadFrameScript("data:," + script,
                                  /* allowDelayedLoad = */ false);
  }

  let iframe1 = document.createElement('iframe');
  iframe1.setAttribute('mozbrowser', 'true');
  iframe1.src = "http://test/tests/dom/browser-element/mochitest/file_browserElement_ThemeColor.html";
  iframe1.addEventListener('mozbrowsermetachange', tests);
  document.body.appendChild(iframe1);

  let numMetaChanges = 0;
  function tests(e) {
    let detail = e.detail;

    switch (numMetaChanges++) {
      case 0: {
        is(detail.name, 'theme-color', 'name matches');
        is(detail.content, 'pink', 'content matches');
        is(detail.type, 'added', 'type matches');

        let script =
          "var meta = content.document.head.querySelector('meta');" +
          "meta.content = 'green';";
        loadFrameScript(script);
        break;
      }

      case 1: {
        is(detail.name, 'theme-color', 'name matches');
        is(detail.content, 'green', 'content matches');
        is(detail.type, 'changed', 'type matches');

        let script =
          "var meta = content.document.createElement('meta');" +
          "meta.name = 'theme-group';" +
          "meta.content = 'theme-productivity';" +
          "content.document.head.appendChild(meta)";
        loadFrameScript(script);
        break;
      }

      case 2: {
        is(detail.name, 'theme-group', 'name matches');
        is(detail.content, 'theme-productivity', 'content matches');
        is(detail.type, 'added', 'type matches');

        let script =
          "var meta = content.document.head.querySelector('meta');" +
          "meta.parentNode.removeChild(meta);";
        loadFrameScript(script);
        break;
      }

      case 3: {
        is(detail.name, 'theme-color', 'name matches');
        is(detail.content, 'green', 'content matches');
        is(detail.type, 'removed', 'type matches');

        SimpleTest.finish();
        break;
      }

      default: {
        ok(false, 'Too many metachange events.');
        break;
      }
    }
  };
}

window.addEventListener('testready', runTest);