1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 'callback_helper.js']);
10 * Base test fixture for ChromeVox end to end tests.
12 * These tests run against production ChromeVox inside of the extension's
13 * background page context.
16 function ChromeVoxE2ETest() {
17 this.callbackHelper_ = new CallbackHelper(this);
20 ChromeVoxE2ETest.prototype = {
21 __proto__: testing.Test.prototype,
25 * No UI in the background context.
27 runAccessibilityChecks: false,
36 testGenCppIncludes: function() {
37 GEN_BLOCK(function() {/*!
38 #include "ash/accessibility_delegate.h"
39 #include "base/bind.h"
40 #include "base/callback.h"
41 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
42 #include "chrome/common/extensions/extension_constants.h"
47 testGenPreamble: function() {
48 GEN_BLOCK(function() {/*!
49 base::Closure load_cb =
50 base::Bind(&chromeos::AccessibilityManager::EnableSpokenFeedback,
51 base::Unretained(chromeos::AccessibilityManager::Get()),
53 ui::A11Y_NOTIFICATION_NONE);
54 WaitForExtension(extension_misc::kChromeVoxExtensionId, load_cb);
59 * Launch a new tab, wait until tab status complete, then run callback.
60 * @param {function() : void} doc Snippet wrapped inside of a function.
61 * @param {function()} callback Called once the document is ready.
63 runWithLoadedTab: function(doc, callback) {
64 this.launchNewTabWithDoc(doc, function(tab) {
65 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
66 if (tabId == tab.id && changeInfo.status == 'complete') {
74 * Launches the given document in a new tab.
75 * @param {function() : void} doc Snippet wrapped inside of a function.
76 * @param {function()} opt_callback Called once the document is created.
78 runWithTab: function(doc, opt_callback) {
79 var docString = TestUtils.extractHtmlFromCommentEncodedString(doc);
80 var url = 'data:text/html,<!doctype html>' +
82 '<!-- chromevox_next_test -->';
87 chrome.tabs.create(createParams, opt_callback);
91 * Send a key to the page.
92 * @param {number} tabId Of the page.
93 * @param {string} key Name of the key (e.g. Down).
94 * @param {string} elementQueryString
96 sendKeyToElement: function(tabId, key, elementQueryString) {
97 var code = TestUtils.extractHtmlFromCommentEncodedString(function() {/*!
98 var target = document.body.querySelector('$1');
100 var evt = document.createEvent('KeyboardEvent');
101 evt.initKeyboardEvent('keydown', true, true, window, '$0', 0, false,
102 false, false, false);
103 document.activeElement.dispatchEvent(evt);
104 */}, [key, elementQueryString]);
106 chrome.tabs.executeScript(tabId, {code: code});
110 * Creates a callback that optionally calls {@code opt_callback} when
111 * called. If this method is called one or more times, then
112 * {@code testDone()} will be called when all callbacks have been called.
113 * @param {Function=} opt_callback Wrapped callback that will have its this
114 * reference bound to the test fixture.
117 newCallback: function(opt_callback) {
118 return this.callbackHelper_.wrap(opt_callback);