Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: chrome/test/data/extensions/platform_apps/web_view/navigation/embedder.js

Issue 17447005: <webview>: Move back, forward, canGoBack, canGoForward, go from content to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@filter_listener
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var embedder = {};
6 embedder.tests = {};
7 embedder.baseGuestURL = '';
8 embedder.guestURL = '';
9
10 window.runTest = function(testName) {
11 if (!embedder.test.testList[testName]) {
12 console.log('Incorrect testName: ' + testName);
13 embedder.test.fail();
14 return;
15 }
16
17 // Run the test.
18 embedder.test.testList[testName]();
19 };
20 // window.* exported functions end.
21
22 /** @private */
23 embedder.setUpGuest_ = function() {
24 document.querySelector('#webview-tag-container').innerHTML =
25 '<webview style="width: 100px; height: 100px;"></webview>';
26 var webview = document.querySelector('webview');
27 if (!webview) {
28 chrome.test.fail('No <webview> element created');
29 }
30 return webview;
31 };
32
33 embedder.getHTMLForGuestWithTitle_ = function(title) {
34 var html =
35 'data:text/html,' +
36 '<html><head><title>%s</title></head>' +
37 '<body>hello world</body>' +
38 '</html>';
39 return html.replace('%s', title);
40 };
41
42 embedder.test = {};
43 embedder.test.succeed = function() {
44 chrome.test.sendMessage('DoneNavigationTest.PASSED');
45 };
46
47 embedder.test.fail = function() {
48 chrome.test.sendMessage('DoneNavigationTest.FAILED');
49 };
50
51 embedder.test.assertEq = function(a, b) {
52 if (a != b) {
53 console.log('assertion failed: ' + a + ' != ' + b);
54 embedder.test.fail();
55 }
56 };
57
58 embedder.test.assertTrue = function(condition) {
59 if (!condition) {
60 console.log('assertion failed: true != ' + condition);
61 embedder.test.fail();
62 }
63 };
64
65 embedder.test.assertFalse = function(condition) {
66 if (condition) {
67 console.log('assertion failed: false != ' + condition);
68 embedder.test.fail();
69 }
70 };
71
72 // Tests begin.
73
74 function testNavigation() {
75 var webview = embedder.setUpGuest_();
76 var step = 1;
77 console.log('run step: ' + step);
78
79 // Verify that canGoBack and canGoForward work as expected.
80 var runStep2 = function() {
81 step = 2;
82 console.log('run step: ' + step);
83 webview.executeScript({
84 code: 'document.title'
85 }, function(results) {
86 embedder.test.assertEq('step1', results[0]);
87 embedder.test.assertFalse(webview.canGoBack());
88 embedder.test.assertFalse(webview.canGoForward());
89 webview.src = embedder.getHTMLForGuestWithTitle_('step2');
90 });
91 };
92
93 // Verify that canGoBack and canGoForward work as expected.
94 var runStep3 = function() {
95 step = 3;
96 console.log('run step: ' + step);
97 webview.executeScript({
98 code: 'document.title'
99 }, function(results) {
100 embedder.test.assertEq('step2', results[0]);
101 embedder.test.assertTrue(webview.canGoBack());
102 embedder.test.assertFalse(webview.canGoForward());
103 webview.back();
104 });
105 };
106
107 // Verify that webview.back works as expected.
108 var runStep4 = function() {
109 step = 4;
110 console.log('run step: ' + step);
111 webview.executeScript({
112 code: 'document.title'
113 }, function(results) {
114 embedder.test.assertEq('step1', results[0]);
115 embedder.test.assertFalse(webview.canGoBack());
116 embedder.test.assertTrue(webview.canGoForward());
117 webview.forward();
118 });
119 };
120
121 // Verify that webview.forward works as expected.
122 var runStep5 = function() {
123 step = 5;
124 console.log('run step: ' + step);
125 webview.executeScript({
126 code: 'document.title'
127 }, function(results) {
128 embedder.test.assertEq('step2', results[0]);
129 embedder.test.assertTrue(webview.canGoBack());
130 embedder.test.assertFalse(webview.canGoForward());
131 webview.src = embedder.getHTMLForGuestWithTitle_('step3');
132 });
133 };
134
135 // Navigate one more time to allow for interesting uses of webview.go.
136 var runStep6 = function() {
137 step = 6;
138 console.log('run step: ' + step);
139 webview.executeScript({
140 code: 'document.title'
141 }, function(results) {
142 embedder.test.assertEq('step3', results[0]);
143 embedder.test.assertTrue(webview.canGoBack());
144 embedder.test.assertFalse(webview.canGoForward());
145 webview.go(-2);
146 });
147 };
148
149 // Verify that webview.go works as expected.
150 var runStep7 = function() {
151 step = 7;
152 console.log('run step: ' + step);
153 webview.executeScript({
154 code: 'document.title'
155 }, function(results) {
156 embedder.test.assertEq('step1', results[0]);
157 embedder.test.assertFalse(webview.canGoBack());
158 embedder.test.assertTrue(webview.canGoForward());
159 embedder.test.succeed();
160 });
161 };
162
163 var onLoadStop = function(e) {
164 switch (step) {
165 case 1:
166 runStep2();
167 break;
168 case 2:
169 runStep3();
170 break;
171 case 3:
172 runStep4();
173 break;
174 case 4:
175 runStep5();
176 break;
177 case 5:
178 runStep6();
179 break;
180 case 6:
181 runStep7();
182 break;
183 default:
184 console.log('unexpected step: ' + step);
185 embedder.test.fail();
186 }
187 };
188 webview.addEventListener('loadstop', onLoadStop);
189 webview.src = embedder.getHTMLForGuestWithTitle_('step1');
190 }
191
192 embedder.test.testList = {
193 'testNavigation': testNavigation
194 };
195
196 onload = function() {
197 chrome.test.getConfig(function(config) {
198 chrome.test.sendMessage("Launched");
199 });
200 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698