Chromium Code Reviews| 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..20c22226756d9d9ea790f5081c385ba1a69b8c0b |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/platform_apps/web_view/navigation/embedder.js |
| @@ -0,0 +1,208 @@ |
| +// 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.runNavigationTest = 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. |
| + |
| +embedder.setUp_ = function(config) { |
| + embedder.baseGuestURL = 'http://localhost:' + config.testServer.port; |
| + embedder.guestURL = embedder.baseGuestURL + |
| + '/files/extensions/platform_apps/web_view/navigation' + |
| + '/guest.html'; |
| + chrome.test.log('Guest url is: ' + embedder.guestURL); |
| +}; |
| + |
| +/** @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: |
|
lazyboy
2013/06/22 04:29:15
log: 'unexpected step: ' + step
Fady Samuel
2013/06/25 15:46:12
Done.
|
| + embedder.test.fail(); |
| + } |
| + }; |
| + webview.addEventListener('loadstop', onLoadStop); |
| + webview.src = embedder.getHTMLForGuestWithTitle_('step1'); |
| +} |
| + |
| +embedder.test.testList = { |
| + 'testNavigation': testNavigation |
| +}; |
| + |
| +onload = function() { |
| + chrome.test.getConfig(function(config) { |
| + embedder.setUp_(config); |
| + chrome.test.sendMessage("Launched"); |
| + }); |
| +}; |