OLD | NEW |
| (Empty) |
1 <script> | |
2 var expectedEventData; | |
3 var capturedEventData; | |
4 | |
5 function expect(data) { | |
6 expectedEventData = data; | |
7 capturedEventData = []; | |
8 } | |
9 | |
10 function checkExpectations() { | |
11 if (capturedEventData.length < expectedEventData.length) { | |
12 return; | |
13 } | |
14 chrome.test.assertEq(JSON.stringify(expectedEventData), | |
15 JSON.stringify(capturedEventData)); | |
16 chrome.test.succeed(); | |
17 } | |
18 | |
19 chrome.experimental.webNavigation.onCommitted.addListener(function(details) { | |
20 console.log('---onCommitted: ' + details.url); | |
21 // normalize details. | |
22 details.timeStamp = 0; | |
23 if (details.frameId != 0) { | |
24 details.frameId = 1; | |
25 } | |
26 capturedEventData.push(details); | |
27 checkExpectations(); | |
28 }); | |
29 | |
30 var getURL = chrome.extension.getURL; | |
31 chrome.tabs.getSelected(null, function(tab) { | |
32 var tabId = tab.id; | |
33 | |
34 chrome.test.runTests([ | |
35 /* Navigates to an URL */ | |
36 function simpleLoad() { | |
37 expect([ | |
38 { frameId: 0, | |
39 tabId: tabId, | |
40 timeStamp: 0, | |
41 transitionQualifiers: "", | |
42 transitionType: "link", | |
43 url: getURL('simpleLoad/a.html') }]); | |
44 chrome.tabs.update(tabId, { url: getURL('simpleLoad/a.html') }); | |
45 }, | |
46 | |
47 /* Navigates to a.html that redirects to b.html (using javascript) | |
48 after a delay of 500ms, so the initial navigation is completed and | |
49 the redirection is marked as client_redirect */ | |
50 function clientRedirect() { | |
51 expect([ | |
52 { frameId: 0, | |
53 tabId: tabId, | |
54 timeStamp: 0, | |
55 transitionQualifiers: "", | |
56 transitionType: "link", | |
57 url: getURL('clientRedirect/a.html') }, | |
58 { frameId: 0, | |
59 tabId: tabId, | |
60 timeStamp: 0, | |
61 transitionQualifiers: "client_redirect", | |
62 transitionType: "link", | |
63 url: getURL('clientRedirect/b.html') }]); | |
64 chrome.tabs.update(tabId, { url: getURL('clientRedirect/a.html') }); | |
65 }, | |
66 | |
67 /* First navigates to a.html, and then to b.html which uses | |
68 history.back() to navigate back to a.html */ | |
69 function forwardBack() { | |
70 expect([ | |
71 { frameId: 0, | |
72 tabId: tabId, | |
73 timeStamp: 0, | |
74 transitionQualifiers: "", | |
75 transitionType: "link", | |
76 url: getURL('forwardBack/a.html') }, | |
77 { frameId: 0, | |
78 tabId: tabId, | |
79 timeStamp: 0, | |
80 transitionQualifiers: "", | |
81 transitionType: "link", | |
82 url: getURL('forwardBack/b.html') }, | |
83 { frameId: 0, | |
84 tabId: tabId, | |
85 timeStamp: 0, | |
86 transitionQualifiers: "forward_back", | |
87 transitionType: "link", | |
88 url: getURL('forwardBack/a.html') }]); | |
89 chrome.tabs.update(tabId, { url: getURL('forwardBack/a.html') }, | |
90 function (tab) { | |
91 chrome.tabs.update(tabId, | |
92 { url: getURL('forwardBack/b.html') }); | |
93 }); | |
94 }, | |
95 | |
96 /* Navigates to a.html which includes b.html as an iframe. b.html | |
97 redirects to c.html. Note that all navigation entries are for | |
98 a.html. Also, b.html does not generate a navigation entry. */ | |
99 function iframe() { | |
100 expect([ | |
101 { frameId: 0, | |
102 tabId: tabId, | |
103 timeStamp: 0, | |
104 transitionQualifiers: "", | |
105 transitionType: "link", | |
106 url: getURL('iframe/a.html') }, | |
107 { frameId: 1, | |
108 tabId: tabId, | |
109 timeStamp: 0, | |
110 transitionQualifiers: "", | |
111 transitionType: "link", | |
112 url: getURL('iframe/a.html') }]); | |
113 chrome.tabs.update(tabId, { url: getURL('iframe/a.html') }); | |
114 }, | |
115 ]); | |
116 }); | |
117 </script> | |
OLD | NEW |