summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/browserElement_CookiesNotThirdParty.js
blob: 32f877786cf872335dcf02bffcf4c810d8de4ee2 (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
/* Any copyright is dedicated to the public domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Bug 806127 - Test that cookies set by <iframe mozbrowser> are not considered
// third-party.
"use strict";

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

function runTest() {
  const innerPage = 'http://example.com/tests/dom/browser-element/mochitest/file_browserElement_CookiesNotThirdParty.html';

  var iframe = document.createElement('iframe');
  iframe.setAttribute('mozbrowser', 'true');

  iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
    if (e.detail.message == 'next') {
      iframe.src = innerPage + '?step=2';
      return;
    }

    if (e.detail.message.startsWith('success:')) {
      ok(true, e.detail.message);
      return;
    }

    if (e.detail.message.startsWith('failure:')) {
      ok(false, e.detail.message);
      return;
    }

    if (e.detail.message == 'finish') {
      SimpleTest.finish();
    }
  });

  // innerPage will set a cookie and then alert('next').  We'll load
  // innerPage?step=2.  That page will check that the cooke exists (despite the
  // fact that we've disabled third-party cookies) and alert('success:') or
  // alert('failure:'), as appropriate.  Finally, the page will
  // alert('finish');
  iframe.src = innerPage;
  document.body.appendChild(iframe);
}

// Disable third-party cookies for this test.
addEventListener('testready', function() {
  SpecialPowers.pushPrefEnv({'set': [['network.cookie.cookieBehavior', 1]]}, runTest);
});