summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_bug822367.js
blob: 0d60c05cd1f51514d6811ca66f1e58fddc3981e3 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * User Override Mixed Content Block - Tests for Bug 822367
 */


const PREF_DISPLAY = "security.mixed_content.block_display_content";
const PREF_ACTIVE = "security.mixed_content.block_active_content";

// We alternate for even and odd test cases to simulate different hosts
const gHttpTestRoot = "https://example.com/browser/browser/base/content/test/general/";
const gHttpTestRoot2 = "https://test1.example.com/browser/browser/base/content/test/general/";

var gTestBrowser = null;

add_task(function* test() {
  yield SpecialPowers.pushPrefEnv({ set: [[ PREF_DISPLAY, true ],
                                          [ PREF_ACTIVE, true  ]] });

  var newTab = gBrowser.addTab();
  gBrowser.selectedTab = newTab;
  gTestBrowser = gBrowser.selectedBrowser;
  newTab.linkedBrowser.stop()

  // Mixed Script Test
  var url = gHttpTestRoot + "file_bug822367_1.html";
  BrowserTestUtils.loadURI(gTestBrowser, url);
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

// Mixed Script Test
add_task(function* MixedTest1A() {
  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});

  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
  gIdentityHandler.disableMixedContentProtection();
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest1B() {
  yield ContentTask.spawn(gTestBrowser, null, function* () {
    yield ContentTaskUtils.waitForCondition(
      () => content.document.getElementById("p1").innerHTML == "hello",
      "Waited too long for mixed script to run in Test 1");
  });
});

// Mixed Display Test - Doorhanger should not appear
add_task(function* MixedTest2() {
  var url = gHttpTestRoot2 + "file_bug822367_2.html";
  BrowserTestUtils.loadURI(gTestBrowser, url);
  yield BrowserTestUtils.browserLoaded(gTestBrowser);

  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: false, passiveLoaded: false});
});

// Mixed Script and Display Test - User Override should cause both the script and the image to load.
add_task(function* MixedTest3() {
  var url = gHttpTestRoot + "file_bug822367_3.html";
  BrowserTestUtils.loadURI(gTestBrowser, url);
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest3A() {
  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});

  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
  gIdentityHandler.disableMixedContentProtection();
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest3B() {
  yield ContentTask.spawn(gTestBrowser, null, function* () {
    let p1 = ContentTaskUtils.waitForCondition(
      () => content.document.getElementById("p1").innerHTML == "hello",
      "Waited too long for mixed script to run in Test 3");
    let p2 = ContentTaskUtils.waitForCondition(
      () => content.document.getElementById("p2").innerHTML == "bye",
      "Waited too long for mixed image to load in Test 3");
    yield Promise.all([ p1, p2 ]);
  });

  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: true});
});

// Location change - User override on one page doesn't propogate to another page after location change.
add_task(function* MixedTest4() {
  var url = gHttpTestRoot2 + "file_bug822367_4.html";
  BrowserTestUtils.loadURI(gTestBrowser, url);
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest4A() {
  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});

  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
  gIdentityHandler.disableMixedContentProtection();
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest4B() {
  let url = gHttpTestRoot + "file_bug822367_4B.html";
  yield ContentTask.spawn(gTestBrowser, url, function* (wantedUrl) {
    yield ContentTaskUtils.waitForCondition(
      () => content.document.location == wantedUrl,
      "Waited too long for mixed script to run in Test 4");
  });
});

add_task(function* MixedTest4C() {
  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});

  yield ContentTask.spawn(gTestBrowser, null, function* () {
    yield ContentTaskUtils.waitForCondition(
      () => content.document.getElementById("p1").innerHTML == "",
      "Mixed script loaded in test 4 after location change!");
  });
});

// Mixed script attempts to load in a document.open()
add_task(function* MixedTest5() {
  var url = gHttpTestRoot + "file_bug822367_5.html";
  BrowserTestUtils.loadURI(gTestBrowser, url);
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest5A() {
  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});

  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
  gIdentityHandler.disableMixedContentProtection();
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest5B() {
  yield ContentTask.spawn(gTestBrowser, null, function* () {
    yield ContentTaskUtils.waitForCondition(
      () => content.document.getElementById("p1").innerHTML == "hello",
      "Waited too long for mixed script to run in Test 5");
  });
});

// Mixed script attempts to load in a document.open() that is within an iframe.
add_task(function* MixedTest6() {
  var url = gHttpTestRoot2 + "file_bug822367_6.html";
  BrowserTestUtils.loadURI(gTestBrowser, url);
  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest6A() {
  gTestBrowser.removeEventListener("load", MixedTest6A, true);
  let {gIdentityHandler} = gTestBrowser.ownerGlobal;

  yield BrowserTestUtils.waitForCondition(
    () => gIdentityHandler._identityBox.classList.contains("mixedActiveBlocked"),
    "Waited too long for control center to get mixed active blocked state");
});

add_task(function* MixedTest6B() {
  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});

  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
  gIdentityHandler.disableMixedContentProtection();

  yield BrowserTestUtils.browserLoaded(gTestBrowser);
});

add_task(function* MixedTest6C() {
  yield ContentTask.spawn(gTestBrowser, null, function* () {
    function test() {
      try {
        return content.document.getElementById("f1").contentDocument.getElementById("p1").innerHTML == "hello";
      } catch (e) {
        return false;
      }
    }

    yield ContentTaskUtils.waitForCondition(test, "Waited too long for mixed script to run in Test 6");
  });
});

add_task(function* MixedTest6D() {
  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: false});
});

add_task(function* cleanup() {
  gBrowser.removeCurrentTab();
});