| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function NavigateInCurrentTabCallback() { | 5 function NavigateInCurrentTabCallback() { |
| 6 this.navigateCalled = false; | 6 this.navigateCalled = false; |
| 7 this.url = undefined; | 7 this.url = undefined; |
| 8 this.callback = function(url) { | 8 this.callback = function(url) { |
| 9 this.navigateCalled = true; | 9 this.navigateCalled = true; |
| 10 this.url = url; | 10 this.url = url; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Given a |navigator|, navigate to |url| in the current tab or new tab, | 32 * Given a |navigator|, navigate to |url| in the current tab or new tab, |
| 33 * depending on the value of |openInNewTab|. Use |viewportChangedCallback| | 33 * depending on the value of |openInNewTab|. Use |viewportChangedCallback| |
| 34 * and |navigateCallback| to check the callbacks, and that the navigation | 34 * and |navigateCallback| to check the callbacks, and that the navigation |
| 35 * to |expectedResultUrl| happened. | 35 * to |expectedResultUrl| happened. |
| 36 */ | 36 */ |
| 37 function doNavigationUrlTest( | 37 function doNavigationUrlTest( |
| 38 navigator, | 38 navigator, |
| 39 url, | 39 url, |
| 40 openInNewTab, | 40 navigateOption, |
| 41 expectedResultUrl, | 41 expectedResultUrl, |
| 42 viewportChangedCallback, | 42 viewportChangedCallback, |
| 43 navigateCallback) { | 43 navigateCallback) { |
| 44 viewportChangedCallback.reset(); | 44 viewportChangedCallback.reset(); |
| 45 navigateCallback.reset(); | 45 navigateCallback.reset(); |
| 46 navigator.navigate(url, openInNewTab); | 46 navigator.navigate(url, navigateOption); |
| 47 chrome.test.assertFalse(viewportChangedCallback.wasCalled); | 47 chrome.test.assertFalse(viewportChangedCallback.wasCalled); |
| 48 chrome.test.assertTrue(navigateCallback.navigateCalled); | 48 chrome.test.assertTrue(navigateCallback.navigateCalled); |
| 49 chrome.test.assertEq(expectedResultUrl, navigateCallback.url); | 49 chrome.test.assertEq(expectedResultUrl, navigateCallback.url); |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Helper function to run doNavigationUrlTest() for the current tab and a new | 53 * Helper function to run doNavigationUrlTest() for the current tab and a new |
| 54 * tab. | 54 * tab. |
| 55 */ | 55 */ |
| 56 function doNavigationUrlTestInCurrentTabAndNewTab( | 56 function doNavigationUrlTestInCurrentTabAndNewTab( |
| 57 navigator, | 57 navigator, |
| 58 url, | 58 url, |
| 59 expectedResultUrl, | 59 expectedResultUrl, |
| 60 viewportChangedCallback, | 60 viewportChangedCallback, |
| 61 navigateInCurrentTabCallback, | 61 navigateInCurrentTabCallback, |
| 62 navigateInNewTabCallback) { | 62 navigateInNewTabCallback) { |
| 63 doNavigationUrlTest(navigator, url, false, expectedResultUrl, | 63 doNavigationUrlTest(navigator, url, |
| 64 Navigator.NavigateOption.OPEN_IN_CURRENT_TAB, expectedResultUrl, |
| 64 viewportChangedCallback, navigateInCurrentTabCallback); | 65 viewportChangedCallback, navigateInCurrentTabCallback); |
| 65 doNavigationUrlTest(navigator, url, true, expectedResultUrl, | 66 doNavigationUrlTest(navigator, url, |
| 67 Navigator.NavigateOption.OPEN_IN_NEW_BACKGROUND_TAB, expectedResultUrl, |
| 66 viewportChangedCallback, navigateInNewTabCallback); | 68 viewportChangedCallback, navigateInNewTabCallback); |
| 67 } | 69 } |
| 68 | 70 |
| 69 var tests = [ | 71 var tests = [ |
| 70 /** | 72 /** |
| 71 * Test navigation within the page, opening a url in the same tab and | 73 * Test navigation within the page, opening a url in the same tab and |
| 72 * opening a url in a new tab. | 74 * opening a url in a new tab. |
| 73 */ | 75 */ |
| 74 function testNavigate() { | 76 function testNavigate() { |
| 75 var mockWindow = new MockWindow(100, 100); | 77 var mockWindow = new MockWindow(100, 100); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 96 | 98 |
| 97 var documentDimensions = new MockDocumentDimensions(); | 99 var documentDimensions = new MockDocumentDimensions(); |
| 98 documentDimensions.addPage(100, 100); | 100 documentDimensions.addPage(100, 100); |
| 99 documentDimensions.addPage(200, 200); | 101 documentDimensions.addPage(200, 200); |
| 100 documentDimensions.addPage(100, 400); | 102 documentDimensions.addPage(100, 400); |
| 101 viewport.setDocumentDimensions(documentDimensions); | 103 viewport.setDocumentDimensions(documentDimensions); |
| 102 viewport.setZoom(1); | 104 viewport.setZoom(1); |
| 103 | 105 |
| 104 mockCallback.reset(); | 106 mockCallback.reset(); |
| 105 // This should move viewport to page 0. | 107 // This should move viewport to page 0. |
| 106 navigator.navigate(url + "#US", false); | 108 navigator.navigate(url + "#US", |
| 109 Navigator.NavigateOption.OPEN_IN_CURRENT_TAB); |
| 107 chrome.test.assertTrue(mockCallback.wasCalled); | 110 chrome.test.assertTrue(mockCallback.wasCalled); |
| 108 chrome.test.assertEq(0, viewport.position.x); | 111 chrome.test.assertEq(0, viewport.position.x); |
| 109 chrome.test.assertEq(0, viewport.position.y); | 112 chrome.test.assertEq(0, viewport.position.y); |
| 110 | 113 |
| 111 mockCallback.reset(); | 114 mockCallback.reset(); |
| 112 navigateInNewTabCallback.reset(); | 115 navigateInNewTabCallback.reset(); |
| 113 // This should open "http://xyz.pdf#US" in a new tab. So current tab | 116 // This should open "http://xyz.pdf#US" in a new tab. So current tab |
| 114 // viewport should not update and viewport position should remain same. | 117 // viewport should not update and viewport position should remain same. |
| 115 navigator.navigate(url + "#US", true); | 118 navigator.navigate(url + "#US", |
| 119 Navigator.NavigateOption.OPEN_IN_NEW_BACKGROUND_TAB); |
| 116 chrome.test.assertFalse(mockCallback.wasCalled); | 120 chrome.test.assertFalse(mockCallback.wasCalled); |
| 117 chrome.test.assertTrue(navigateInNewTabCallback.navigateCalled); | 121 chrome.test.assertTrue(navigateInNewTabCallback.navigateCalled); |
| 118 chrome.test.assertEq(0, viewport.position.x); | 122 chrome.test.assertEq(0, viewport.position.x); |
| 119 chrome.test.assertEq(0, viewport.position.y); | 123 chrome.test.assertEq(0, viewport.position.y); |
| 120 | 124 |
| 121 mockCallback.reset(); | 125 mockCallback.reset(); |
| 122 // This should move viewport to page 2. | 126 // This should move viewport to page 2. |
| 123 navigator.navigate(url + "#UY", false); | 127 navigator.navigate(url + "#UY", |
| 128 Navigator.NavigateOption.OPEN_IN_CURRENT_TAB); |
| 124 chrome.test.assertTrue(mockCallback.wasCalled); | 129 chrome.test.assertTrue(mockCallback.wasCalled); |
| 125 chrome.test.assertEq(0, viewport.position.x); | 130 chrome.test.assertEq(0, viewport.position.x); |
| 126 chrome.test.assertEq(300, viewport.position.y); | 131 chrome.test.assertEq(300, viewport.position.y); |
| 127 | 132 |
| 128 mockCallback.reset(); | 133 mockCallback.reset(); |
| 129 navigateInCurrentTabCallback.reset(); | 134 navigateInCurrentTabCallback.reset(); |
| 130 // #ABC is not a named destination in the page so viewport should not | 135 // #ABC is not a named destination in the page so viewport should not |
| 131 // update and viewport position should remain same. As this link will open | 136 // update and viewport position should remain same. As this link will open |
| 132 // in the same tab. | 137 // in the same tab. |
| 133 navigator.navigate(url + "#ABC", false); | 138 navigator.navigate(url + "#ABC", |
| 139 Navigator.NavigateOption.OPEN_IN_CURRENT_TAB); |
| 134 chrome.test.assertFalse(mockCallback.wasCalled); | 140 chrome.test.assertFalse(mockCallback.wasCalled); |
| 135 chrome.test.assertTrue(navigateInCurrentTabCallback.navigateCalled); | 141 chrome.test.assertTrue(navigateInCurrentTabCallback.navigateCalled); |
| 136 chrome.test.assertEq(0, viewport.position.x); | 142 chrome.test.assertEq(0, viewport.position.x); |
| 137 chrome.test.assertEq(300, viewport.position.y); | 143 chrome.test.assertEq(300, viewport.position.y); |
| 138 | 144 |
| 139 chrome.test.succeed(); | 145 chrome.test.succeed(); |
| 140 }, | 146 }, |
| 141 /** | 147 /** |
| 142 * Test opening a url in the same tab and opening a url in a new tab for | 148 * Test opening a url in the same tab and opening a url in a new tab for |
| 143 * a http:// url as the current location. The destination url may not have | 149 * a http:// url as the current location. The destination url may not have |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 navigateInNewTabCallback); | 294 navigateInNewTabCallback); |
| 289 | 295 |
| 290 chrome.test.succeed(); | 296 chrome.test.succeed(); |
| 291 } | 297 } |
| 292 ]; | 298 ]; |
| 293 | 299 |
| 294 var scriptingAPI = new PDFScriptingAPI(window, window); | 300 var scriptingAPI = new PDFScriptingAPI(window, window); |
| 295 scriptingAPI.setLoadCallback(function() { | 301 scriptingAPI.setLoadCallback(function() { |
| 296 chrome.test.runTests(tests); | 302 chrome.test.runTests(tests); |
| 297 }); | 303 }); |
| OLD | NEW |