browser/base/content/test/plugins/browser_pageInfo_plugins.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 let gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
     2 let gPageInfo = null;
     3 let gNextTest = null;
     4 let gTestBrowser = null;
     5 let gPluginHost = Components.classes["@mozilla.org/plugin/host;1"]
     6                     .getService(Components.interfaces.nsIPluginHost);
     7 let gPermissionManager = Components.classes["@mozilla.org/permissionmanager;1"]
     8                            .getService(Components.interfaces.nsIPermissionManager);
     9 let gTestPermissionString = gPluginHost.getPermissionStringForType("application/x-test");
    10 let gSecondTestPermissionString = gPluginHost.getPermissionStringForType("application/x-second-test");
    12 function doOnPageLoad(url, continuation) {
    13   gNextTest = continuation;
    14   gTestBrowser.addEventListener("load", pageLoad, true);
    15   gTestBrowser.contentWindow.location = url;
    16 }
    18 function pageLoad() {
    19   gTestBrowser.removeEventListener("load", pageLoad);
    20   // The plugin events are async dispatched and can come after the load event
    21   // This just allows the events to fire before we then go on to test the states
    22   executeSoon(gNextTest);
    23 }
    25 function doOnOpenPageInfo(continuation) {
    26   Services.obs.addObserver(pageInfoObserve, "page-info-dialog-loaded", false);
    27   gNextTest = continuation;
    28   // An explanation: it looks like the test harness complains about leaked
    29   // windows if we don't keep a reference to every window we've opened.
    30   // So, don't reuse pointers to opened Page Info windows - simply append
    31   // to this list.
    32   gPageInfo = BrowserPageInfo(null, "permTab");
    33 }
    35 function pageInfoObserve(win, topic, data) {
    36   Services.obs.removeObserver(pageInfoObserve, "page-info-dialog-loaded");
    37   executeSoon(gNextTest);
    38 }
    40 function finishTest() {
    41   gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString);
    42   gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString);
    43   Services.prefs.clearUserPref("plugins.click_to_play");
    44   gBrowser.removeCurrentTab();
    46   gPageInfo = null;
    47   gNextTest = null;
    48   gTestBrowser = null;
    49   gPluginHost = null;
    50   gPermissionManager = null;
    52   executeSoon(finish);
    53 }
    55 function test() {
    56   waitForExplicitFinish();
    57   Services.prefs.setBoolPref("plugins.click_to_play", true);
    58   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    59   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Second Test Plug-in");
    60   gBrowser.selectedTab = gBrowser.addTab();
    61   gTestBrowser = gBrowser.selectedBrowser;
    62   gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString);
    63   gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString);
    64   doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart1a);
    65 }
    67 // The first test plugin is CtP and the second test plugin is enabled.
    68 function testPart1a() {
    69   let test = gTestBrowser.contentDocument.getElementById("test");
    70   let objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent);
    71   ok(!objLoadingContent.activated, "part 1a: Test plugin should not be activated");
    72   let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA");
    73   let objLoadingContent = secondtest.QueryInterface(Ci.nsIObjectLoadingContent);
    74   ok(objLoadingContent.activated, "part 1a: Second Test plugin should be activated");
    76   doOnOpenPageInfo(testPart1b);
    77 }
    79 function testPart1b() {
    80   let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup");
    81   let testRadioDefault = gPageInfo.document.getElementById(gTestPermissionString + "#0");
    83   var qString = "#" + gTestPermissionString.replace(':', '\\:') + "\\#0";
    84   is(testRadioGroup.selectedItem, testRadioDefault, "part 1b: Test radio group should be set to 'Default'");
    85   let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1");
    86   testRadioGroup.selectedItem = testRadioAllow;
    87   testRadioAllow.doCommand();
    89   let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup");
    90   let secondtestRadioDefault = gPageInfo.document.getElementById(gSecondTestPermissionString + "#0");
    91   is(secondtestRadioGroup.selectedItem, secondtestRadioDefault, "part 1b: Second Test radio group should be set to 'Default'");
    92   let secondtestRadioAsk = gPageInfo.document.getElementById(gSecondTestPermissionString + "#3");
    93   secondtestRadioGroup.selectedItem = secondtestRadioAsk;
    94   secondtestRadioAsk.doCommand();
    96   doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart2);
    97 }
    99 // Now, the Test plugin should be allowed, and the Test2 plugin should be CtP
   100 function testPart2() {
   101   let test = gTestBrowser.contentDocument.getElementById("test").
   102     QueryInterface(Ci.nsIObjectLoadingContent);
   103   ok(test.activated, "part 2: Test plugin should be activated");
   105   let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA").
   106     QueryInterface(Ci.nsIObjectLoadingContent);
   107   ok(!secondtest.activated, "part 2: Second Test plugin should not be activated");
   108   is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY,
   109      "part 2: Second test plugin should be click-to-play.");
   111   let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup");
   112   let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1");
   113   is(testRadioGroup.selectedItem, testRadioAllow, "part 2: Test radio group should be set to 'Allow'");
   114   let testRadioBlock = gPageInfo.document.getElementById(gTestPermissionString + "#2");
   115   testRadioGroup.selectedItem = testRadioBlock;
   116   testRadioBlock.doCommand();
   118   let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup");
   119   let secondtestRadioAsk = gPageInfo.document.getElementById(gSecondTestPermissionString + "#3");
   120   is(secondtestRadioGroup.selectedItem, secondtestRadioAsk, "part 2: Second Test radio group should be set to 'Always Ask'");
   121   let secondtestRadioBlock = gPageInfo.document.getElementById(gSecondTestPermissionString + "#2");
   122   secondtestRadioGroup.selectedItem = secondtestRadioBlock;
   123   secondtestRadioBlock.doCommand();
   125   doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart3);
   126 }
   128 // Now, all the things should be blocked
   129 function testPart3() {
   130   let test = gTestBrowser.contentDocument.getElementById("test").
   131     QueryInterface(Ci.nsIObjectLoadingContent);
   132   ok(!test.activated, "part 3: Test plugin should not be activated");
   133   is(test.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED,
   134     "part 3: Test plugin should be marked as PLUGIN_DISABLED");
   136   let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA").
   137     QueryInterface(Ci.nsIObjectLoadingContent);
   139   ok(!secondtest.activated, "part 3: Second Test plugin should not be activated");
   140   is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED,
   141      "part 3: Second test plugin should be marked as PLUGIN_DISABLED");
   143   // reset permissions
   144   gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString);
   145   gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString);
   146   // check that changing the permissions affects the radio state in the
   147   // open Page Info window
   148   let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup");
   149   let testRadioDefault = gPageInfo.document.getElementById(gTestPermissionString + "#0");
   150   is(testRadioGroup.selectedItem, testRadioDefault, "part 3: Test radio group should be set to 'Default'");
   151   let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup");
   152   let secondtestRadioDefault = gPageInfo.document.getElementById(gSecondTestPermissionString + "#0");
   153   is(secondtestRadioGroup.selectedItem, secondtestRadioDefault, "part 3: Second Test radio group should be set to 'Default'");
   155   doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart4a);
   156 }
   158 // Now test that setting permission directly (as from the popup notification)
   159 // immediately influences Page Info.
   160 function testPart4a() {
   161   // simulate "allow" from the doorhanger
   162   gPermissionManager.add(gTestBrowser.currentURI, gTestPermissionString, Ci.nsIPermissionManager.ALLOW_ACTION);
   163   gPermissionManager.add(gTestBrowser.currentURI, gSecondTestPermissionString, Ci.nsIPermissionManager.ALLOW_ACTION);
   165   // check (again) that changing the permissions affects the radio state in the
   166   // open Page Info window
   167   let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup");
   168   let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1");
   169   is(testRadioGroup.selectedItem, testRadioAllow, "part 4a: Test radio group should be set to 'Allow'");
   170   let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup");
   171   let secondtestRadioAllow = gPageInfo.document.getElementById(gSecondTestPermissionString + "#1");
   172   is(secondtestRadioGroup.selectedItem, secondtestRadioAllow, "part 4a: Second Test radio group should be set to 'Always Allow'");
   174   // now close Page Info and see that it opens with the right settings
   175   gPageInfo.close();
   176   doOnOpenPageInfo(testPart4b);
   177 }
   179 // check that "always allow" resulted in the radio buttons getting set to allow
   180 function testPart4b() {
   181   let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup");
   182   let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1");
   183   is(testRadioGroup.selectedItem, testRadioAllow, "part 4b: Test radio group should be set to 'Allow'");
   185   let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup");
   186   let secondtestRadioAllow = gPageInfo.document.getElementById(gSecondTestPermissionString + "#1");
   187   is(secondtestRadioGroup.selectedItem, secondtestRadioAllow, "part 4b: Second Test radio group should be set to 'Allow'");
   189   Services.prefs.setBoolPref("plugins.click_to_play", false);
   190   gPageInfo.close();
   191   finishTest();
   192 }

mercurial