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

Unified Diff: chrome/test/data/pdf/navigator_test.js

Issue 838723003: Testcases for nameddests and navigate for PDF (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 11 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
« no previous file with comments | « chrome/browser/resources/pdf/pdf_extension_test.cc ('k') | chrome/test/data/pdf/params_parser_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/pdf/navigator_test.js
diff --git a/chrome/test/data/pdf/navigator_test.js b/chrome/test/data/pdf/navigator_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..d068a96ec81dc350ff6995ff313a7fdb8dc36b4b
--- /dev/null
+++ b/chrome/test/data/pdf/navigator_test.js
@@ -0,0 +1,98 @@
+// Copyright 2015 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.
+
+function NavigateInCurrentTabCallback() {
+ this.navigateInCurrentTabCalled = false;
+ this.callback = function() {
+ this.navigateInCurrentTabCalled = true;
+ }.bind(this);
+ this.reset = function() {
+ this.navigateInCurrentTabCalled = false;
+ };
+}
+
+function NavigateInNewTabCallback() {
+ this.navigateInNewTabCalled = false;
+ this.callback = function() {
+ this.navigateInNewTabCalled = true;
+ }.bind(this);
+ this.reset = function() {
+ this.navigateInNewTabCalled = false;
+ };
+}
+
+var tests = [
+ /**
+ * Test navigation within the page, opening a url in the same tab and
+ * opening a url in the new tab.
+ */
+ function testNavigate() {
+ var mockWindow = new MockWindow(100, 100);
+ var mockSizer = new MockSizer();
+ var mockCallback = new MockViewportChangedCallback();
+ var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
+ function() {}, function() {}, 0, 0);
+
+ var paramsParser = new OpenPDFParamsParser();
+ paramsParser.namedDestinations['US'] = 0;
+ paramsParser.namedDestinations['UY'] = 2;
+ var url = "http://xyz.pdf";
+
+ var navigateInCurrentTabCallback = new NavigateInCurrentTabCallback();
+ var navigateInNewTabCallback = new NavigateInNewTabCallback();
+ var navigator = new Navigator(url, viewport, paramsParser,
+ navigateInCurrentTabCallback.callback,
+ navigateInNewTabCallback.callback);
+
+ var documentDimensions = new MockDocumentDimensions();
+ documentDimensions.addPage(100, 100);
+ documentDimensions.addPage(200, 200);
+ documentDimensions.addPage(100, 400);
+ viewport.setDocumentDimensions(documentDimensions);
+ viewport.setZoom(1);
+
+ mockCallback.reset();
+ // This should move viewport to page 0.
+ navigator.navigate(url + "#US", false);
+ chrome.test.assertTrue(mockCallback.wasCalled);
+ chrome.test.assertEq(0, viewport.position.x);
+ chrome.test.assertEq(0, viewport.position.y);
+
+ mockCallback.reset();
+ navigateInNewTabCallback.reset();
+ // This should open "http://xyz.pdf#US" in a new tab. So current tab
+ // viewport should not update and viewport position should remain same.
+ navigator.navigate(url + "#US", true);
+ chrome.test.assertFalse(mockCallback.wasCalled);
+ chrome.test.assertTrue(navigateInNewTabCallback.navigateInNewTabCalled);
+ chrome.test.assertEq(0, viewport.position.x);
+ chrome.test.assertEq(0, viewport.position.y);
+
+ mockCallback.reset();
+ // This should move viewport to page 2.
+ navigator.navigate(url + "#UY", false);
+ chrome.test.assertTrue(mockCallback.wasCalled);
+ chrome.test.assertEq(0, viewport.position.x);
+ chrome.test.assertEq(300, viewport.position.y);
+
+ mockCallback.reset();
+ navigateInCurrentTabCallback.reset();
+ // #ABC is not a named destination in the page so viewport should not
+ // update and viewport position should remain same. As this link will open
+ // in the same tab.
+ navigator.navigate(url + "#ABC", false);
+ chrome.test.assertFalse(mockCallback.wasCalled);
+ chrome.test.assertTrue(
+ navigateInCurrentTabCallback.navigateInCurrentTabCalled);
+ chrome.test.assertEq(0, viewport.position.x);
+ chrome.test.assertEq(300, viewport.position.y);
+
+ chrome.test.succeed();
+ }
+];
+
+var scriptingAPI = new PDFScriptingAPI(window, window);
+scriptingAPI.setLoadCallback(function() {
+ chrome.test.runTests(tests);
+});
« no previous file with comments | « chrome/browser/resources/pdf/pdf_extension_test.cc ('k') | chrome/test/data/pdf/params_parser_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698