1-
21"use strict" ;
32
43const SIMPLE_HTML = "data:text/html,<html><head></head><body></body></html>" ;
@@ -10,8 +9,7 @@ const SIMPLE_HTML = "data:text/html,<html><head></head><body></body></html>";
109 */
1110function getManifestDir ( ) {
1211 let path = getTestFilePath ( "browser_docshell_type_editor" ) ;
13- let file = Cc [ "@mozilla.org/file/local;1" ]
14- . createInstance ( Ci . nsIFile ) ;
12+ let file = Cc [ "@mozilla.org/file/local;1" ] . createInstance ( Ci . nsIFile ) ;
1513 file . initWithPath ( path ) ;
1614 return file ;
1715}
@@ -28,92 +26,111 @@ add_task(async function() {
2826 let manifestDir = getManifestDir ( ) ;
2927 Components . manager . addBootstrappedManifestLocation ( manifestDir ) ;
3028
31- await BrowserTestUtils . withNewTab ( {
32- gBrowser,
33- url : SIMPLE_HTML
34- } , async function ( browser ) {
35- await ContentTask . spawn ( browser , null , async function ( ) {
36- let rootDocShell = docShell . QueryInterface ( Ci . nsIDocShellTreeItem )
37- . rootTreeItem
38- . QueryInterface ( Ci . nsIInterfaceRequestor )
39- . getInterface ( Ci . nsIDocShell ) ;
40- let defaultAppType = rootDocShell . appType ;
41-
42- rootDocShell . appType = Ci . nsIDocShell . APP_TYPE_EDITOR ;
43-
44- is ( rootDocShell . appType , Ci . nsIDocShell . APP_TYPE_EDITOR ,
45- "sanity check: appType after update should be type editor" ) ;
46-
47-
48- return new Promise ( resolve => {
49- let doc = content . document ;
50- let image = doc . createElement ( "img" ) ;
51- image . onload = function ( ) {
52- ok ( true , "APP_TYPE_EDITOR is allowed to load privileged image" ) ;
53- // restore appType of rootDocShell before moving on to the next test
54- rootDocShell . appType = defaultAppType ;
55- resolve ( ) ;
56- }
57- image . onerror = function ( ) {
58- ok ( false , "APP_TYPE_EDITOR is allowed to load privileged image" ) ;
59- // restore appType of rootDocShell before moving on to the next test
60- rootDocShell . appType = defaultAppType ;
61- resolve ( ) ;
62- }
63- doc . body . appendChild ( image ) ;
64- image . src = "chrome://test1/skin/privileged.png" ;
29+ await BrowserTestUtils . withNewTab (
30+ {
31+ gBrowser,
32+ url : SIMPLE_HTML ,
33+ } ,
34+ async function ( browser ) {
35+ await ContentTask . spawn ( browser , null , async function ( ) {
36+ let rootDocShell = docShell
37+ . QueryInterface ( Ci . nsIDocShellTreeItem )
38+ . rootTreeItem . QueryInterface ( Ci . nsIInterfaceRequestor )
39+ . getInterface ( Ci . nsIDocShell ) ;
40+ let defaultAppType = rootDocShell . appType ;
41+
42+ rootDocShell . appType = Ci . nsIDocShell . APP_TYPE_EDITOR ;
43+
44+ is (
45+ rootDocShell . appType ,
46+ Ci . nsIDocShell . APP_TYPE_EDITOR ,
47+ "sanity check: appType after update should be type editor"
48+ ) ;
49+
50+ return new Promise ( resolve => {
51+ let doc = content . document ;
52+ let image = doc . createElement ( "img" ) ;
53+ image . onload = function ( ) {
54+ ok ( true , "APP_TYPE_EDITOR is allowed to load privileged image" ) ;
55+ // restore appType of rootDocShell before moving on to the next test
56+ rootDocShell . appType = defaultAppType ;
57+ resolve ( ) ;
58+ } ;
59+ image . onerror = function ( ) {
60+ ok ( false , "APP_TYPE_EDITOR is allowed to load privileged image" ) ;
61+ // restore appType of rootDocShell before moving on to the next test
62+ rootDocShell . appType = defaultAppType ;
63+ resolve ( ) ;
64+ } ;
65+ doc . body . appendChild ( image ) ;
66+ image . src = "chrome://test1/skin/privileged.png" ;
67+ } ) ;
6568 } ) ;
66- } ) ;
67- } ) ;
69+ }
70+ ) ;
6871
6972 Components . manager . removeBootstrappedManifestLocation ( manifestDir ) ;
7073} ) ;
7174
7275add_task ( async function ( ) {
73- info ( "docshell of appType APP_TYPE_UNKNOWN can *not* access privileged images." ) ;
76+ info (
77+ "docshell of appType APP_TYPE_UNKNOWN can *not* access privileged images."
78+ ) ;
7479
7580 // Load a temporary manifest adding a route to a privileged image
7681 let manifestDir = getManifestDir ( ) ;
7782 Components . manager . addBootstrappedManifestLocation ( manifestDir ) ;
7883
79- await BrowserTestUtils . withNewTab ( {
80- gBrowser,
81- url : SIMPLE_HTML
82- } , async function ( browser ) {
83- await ContentTask . spawn ( browser , null , async function ( ) {
84- let rootDocShell = docShell . QueryInterface ( Ci . nsIDocShellTreeItem )
85- . rootTreeItem
86- . QueryInterface ( Ci . nsIInterfaceRequestor )
87- . getInterface ( Ci . nsIDocShell ) ;
88- let defaultAppType = rootDocShell . appType ;
89-
90- rootDocShell . appType = Ci . nsIDocShell . APP_TYPE_UNKNOWN ;
91-
92- is ( rootDocShell . appType , Ci . nsIDocShell . APP_TYPE_UNKNOWN ,
93- "sanity check: appType of docshell should be unknown" ) ;
94-
95- return new Promise ( resolve => {
96- let doc = content . document ;
97- let image = doc . createElement ( "img" ) ;
98- image . onload = function ( ) {
99- ok ( false , "APP_TYPE_UNKNOWN is *not* allowed to acces privileged image" ) ;
100- // restore appType of rootDocShell before moving on to the next test
101- rootDocShell . appType = defaultAppType ;
102- resolve ( ) ;
103- }
104- image . onerror = function ( ) {
105- ok ( true , "APP_TYPE_UNKNOWN is *not* allowed to acces privileged image" ) ;
106- // restore appType of rootDocShell before moving on to the next test
107- rootDocShell . appType = defaultAppType ;
108- resolve ( ) ;
109- }
110- doc . body . appendChild ( image ) ;
111- // Set the src via wrappedJSObject so the load is triggered with
112- // the content page's principal rather than ours.
113- image . wrappedJSObject . src = "chrome://test1/skin/privileged.png" ;
84+ await BrowserTestUtils . withNewTab (
85+ {
86+ gBrowser,
87+ url : SIMPLE_HTML ,
88+ } ,
89+ async function ( browser ) {
90+ await ContentTask . spawn ( browser , null , async function ( ) {
91+ let rootDocShell = docShell
92+ . QueryInterface ( Ci . nsIDocShellTreeItem )
93+ . rootTreeItem . QueryInterface ( Ci . nsIInterfaceRequestor )
94+ . getInterface ( Ci . nsIDocShell ) ;
95+ let defaultAppType = rootDocShell . appType ;
96+
97+ rootDocShell . appType = Ci . nsIDocShell . APP_TYPE_UNKNOWN ;
98+
99+ is (
100+ rootDocShell . appType ,
101+ Ci . nsIDocShell . APP_TYPE_UNKNOWN ,
102+ "sanity check: appType of docshell should be unknown"
103+ ) ;
104+
105+ return new Promise ( resolve => {
106+ let doc = content . document ;
107+ let image = doc . createElement ( "img" ) ;
108+ image . onload = function ( ) {
109+ ok (
110+ false ,
111+ "APP_TYPE_UNKNOWN is *not* allowed to acces privileged image"
112+ ) ;
113+ // restore appType of rootDocShell before moving on to the next test
114+ rootDocShell . appType = defaultAppType ;
115+ resolve ( ) ;
116+ } ;
117+ image . onerror = function ( ) {
118+ ok (
119+ true ,
120+ "APP_TYPE_UNKNOWN is *not* allowed to acces privileged image"
121+ ) ;
122+ // restore appType of rootDocShell before moving on to the next test
123+ rootDocShell . appType = defaultAppType ;
124+ resolve ( ) ;
125+ } ;
126+ doc . body . appendChild ( image ) ;
127+ // Set the src via wrappedJSObject so the load is triggered with
128+ // the content page's principal rather than ours.
129+ image . wrappedJSObject . src = "chrome://test1/skin/privileged.png" ;
130+ } ) ;
114131 } ) ;
115- } ) ;
116- } ) ;
132+ }
133+ ) ;
117134
118135 Components . manager . removeBootstrappedManifestLocation ( manifestDir ) ;
119136} ) ;
0 commit comments