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

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

Issue 1359613002: PDF: Prevent left/right arrow shortcuts when a PDF text field is focused. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename variable Created 5 years, 3 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.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/pdf/page_change_test.js
diff --git a/chrome/test/data/pdf/page_change_test.js b/chrome/test/data/pdf/page_change_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..85395d676051870188d278f60336848918cd3803
--- /dev/null
+++ b/chrome/test/data/pdf/page_change_test.js
@@ -0,0 +1,74 @@
+// 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 resetDocument() {
+ window.viewer.viewport.goToPage(0);
+ window.viewer.viewport.setZoom(1);
+ window.viewer.isFormFieldFocused_ = false;
+}
+
+function getCurrentPage() {
+ return window.viewer.viewport.getMostVisiblePage();
+}
+
+var tests = [
+ /**
+ * Test that the left/right arrows change page back and forth.
+ */
+ function testPageChangesWithArrows() {
+ // Right arrow -> Go to page 2.
+ MockInteractions.pressAndReleaseKeyOn(document, 39);
+ chrome.test.assertEq(1, getCurrentPage());
+
+ // Left arrow -> Back to page 1.
+ MockInteractions.pressAndReleaseKeyOn(document, 37);
+ chrome.test.assertEq(0, getCurrentPage());
+
+ resetDocument();
+ chrome.test.succeed();
+ },
+
+ /**
+ * Test that when a PDF form field is focused, the left/right shortcuts are
+ * disabled. This doesn't test the plugin side of this feature.
+ */
+ function testPageDoesntChangeWhenFormFocused() {
+ // This should be set by a message from plugin -> page when a field is
+ // focused.
+ window.viewer.isFormFieldFocused_ = true;
+
+ // Page should not change when left/right are pressed.
+ MockInteractions.pressAndReleaseKeyOn(document, 39);
+ chrome.test.assertEq(0, getCurrentPage());
+
+ MockInteractions.pressAndReleaseKeyOn(document, 37);
+ chrome.test.assertEq(0, getCurrentPage());
+
+ resetDocument();
+ chrome.test.succeed();
+ },
+
+ /**
+ * Test that when the document is in fit to page, pressing page up/page down
+ * changes page back/forth.
+ */
+ function testPageDownInFitPage() {
+ window.viewer.viewport.fitToPage();
+
+ // Page down -> Go to page 2.
+ MockInteractions.pressAndReleaseKeyOn(document, 34);
+ chrome.test.assertEq(1, getCurrentPage());
+
+ // Page up -> Back to page 1.
+ MockInteractions.pressAndReleaseKeyOn(document, 33);
+ chrome.test.assertEq(0, getCurrentPage());
+
+ resetDocument();
+ chrome.test.succeed();
+ }
+];
+
+importTestHelpers().then(function() {
+ chrome.test.runTests(tests);
+});
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698