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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/platform_apps/web_view/navigation/embedder.js
diff --git a/chrome/test/data/extensions/platform_apps/web_view/navigation/embedder.js b/chrome/test/data/extensions/platform_apps/web_view/navigation/embedder.js
new file mode 100644
index 0000000000000000000000000000000000000000..3c10d8d778197a3203f46ccde17c82f237c7ddb4
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/web_view/navigation/embedder.js
@@ -0,0 +1,200 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var embedder = {};
+embedder.tests = {};
+embedder.baseGuestURL = '';
+embedder.guestURL = '';
+
+window.runTest = function(testName) {
+ if (!embedder.test.testList[testName]) {
+ console.log('Incorrect testName: ' + testName);
+ embedder.test.fail();
+ return;
+ }
+
+ // Run the test.
+ embedder.test.testList[testName]();
+};
+// window.* exported functions end.
+
+/** @private */
+embedder.setUpGuest_ = function() {
+ document.querySelector('#webview-tag-container').innerHTML =
+ '<webview style="width: 100px; height: 100px;"></webview>';
+ var webview = document.querySelector('webview');
+ if (!webview) {
+ chrome.test.fail('No <webview> element created');
+ }
+ return webview;
+};
+
+embedder.getHTMLForGuestWithTitle_ = function(title) {
+ var html =
+ 'data:text/html,' +
+ '<html><head><title>%s</title></head>' +
+ '<body>hello world</body>' +
+ '</html>';
+ return html.replace('%s', title);
+};
+
+embedder.test = {};
+embedder.test.succeed = function() {
+ chrome.test.sendMessage('DoneNavigationTest.PASSED');
+};
+
+embedder.test.fail = function() {
+ chrome.test.sendMessage('DoneNavigationTest.FAILED');
+};
+
+embedder.test.assertEq = function(a, b) {
+ if (a != b) {
+ console.log('assertion failed: ' + a + ' != ' + b);
+ embedder.test.fail();
+ }
+};
+
+embedder.test.assertTrue = function(condition) {
+ if (!condition) {
+ console.log('assertion failed: true != ' + condition);
+ embedder.test.fail();
+ }
+};
+
+embedder.test.assertFalse = function(condition) {
+ if (condition) {
+ console.log('assertion failed: false != ' + condition);
+ embedder.test.fail();
+ }
+};
+
+// Tests begin.
+
+function testNavigation() {
+ var webview = embedder.setUpGuest_();
+ var step = 1;
+ console.log('run step: ' + step);
+
+ // Verify that canGoBack and canGoForward work as expected.
+ var runStep2 = function() {
+ step = 2;
+ console.log('run step: ' + step);
+ webview.executeScript({
+ code: 'document.title'
+ }, function(results) {
+ embedder.test.assertEq('step1', results[0]);
+ embedder.test.assertFalse(webview.canGoBack());
+ embedder.test.assertFalse(webview.canGoForward());
+ webview.src = embedder.getHTMLForGuestWithTitle_('step2');
+ });
+ };
+
+ // Verify that canGoBack and canGoForward work as expected.
+ var runStep3 = function() {
+ step = 3;
+ console.log('run step: ' + step);
+ webview.executeScript({
+ code: 'document.title'
+ }, function(results) {
+ embedder.test.assertEq('step2', results[0]);
+ embedder.test.assertTrue(webview.canGoBack());
+ embedder.test.assertFalse(webview.canGoForward());
+ webview.back();
+ });
+ };
+
+ // Verify that webview.back works as expected.
+ var runStep4 = function() {
+ step = 4;
+ console.log('run step: ' + step);
+ webview.executeScript({
+ code: 'document.title'
+ }, function(results) {
+ embedder.test.assertEq('step1', results[0]);
+ embedder.test.assertFalse(webview.canGoBack());
+ embedder.test.assertTrue(webview.canGoForward());
+ webview.forward();
+ });
+ };
+
+ // Verify that webview.forward works as expected.
+ var runStep5 = function() {
+ step = 5;
+ console.log('run step: ' + step);
+ webview.executeScript({
+ code: 'document.title'
+ }, function(results) {
+ embedder.test.assertEq('step2', results[0]);
+ embedder.test.assertTrue(webview.canGoBack());
+ embedder.test.assertFalse(webview.canGoForward());
+ webview.src = embedder.getHTMLForGuestWithTitle_('step3');
+ });
+ };
+
+ // Navigate one more time to allow for interesting uses of webview.go.
+ var runStep6 = function() {
+ step = 6;
+ console.log('run step: ' + step);
+ webview.executeScript({
+ code: 'document.title'
+ }, function(results) {
+ embedder.test.assertEq('step3', results[0]);
+ embedder.test.assertTrue(webview.canGoBack());
+ embedder.test.assertFalse(webview.canGoForward());
+ webview.go(-2);
+ });
+ };
+
+ // Verify that webview.go works as expected.
+ var runStep7 = function() {
+ step = 7;
+ console.log('run step: ' + step);
+ webview.executeScript({
+ code: 'document.title'
+ }, function(results) {
+ embedder.test.assertEq('step1', results[0]);
+ embedder.test.assertFalse(webview.canGoBack());
+ embedder.test.assertTrue(webview.canGoForward());
+ embedder.test.succeed();
+ });
+ };
+
+ var onLoadStop = function(e) {
+ switch (step) {
+ case 1:
+ runStep2();
+ break;
+ case 2:
+ runStep3();
+ break;
+ case 3:
+ runStep4();
+ break;
+ case 4:
+ runStep5();
+ break;
+ case 5:
+ runStep6();
+ break;
+ case 6:
+ runStep7();
+ break;
+ default:
+ console.log('unexpected step: ' + step);
+ embedder.test.fail();
+ }
+ };
+ webview.addEventListener('loadstop', onLoadStop);
+ webview.src = embedder.getHTMLForGuestWithTitle_('step1');
+}
+
+embedder.test.testList = {
+ 'testNavigation': testNavigation
+};
+
+onload = function() {
+ chrome.test.getConfig(function(config) {
+ chrome.test.sendMessage("Launched");
+ });
+};

Powered by Google App Engine
This is Rietveld 408576698