Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/chromevox_browsertest.cc |
| diff --git a/chrome/browser/resources/chromeos/chromevox/chromevox_browsertest.cc b/chrome/browser/resources/chromeos/chromevox/chromevox_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2198a46ccd642506dbfc3a69cf57cce1724bd6da |
| --- /dev/null |
| +++ b/chrome/browser/resources/chromeos/chromevox/chromevox_browsertest.cc |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2014 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. |
| + |
| +#include "chrome/browser/resources/chromeos/chromevox/chromevox_browsertest.h" |
| + |
| +#include "ash/accessibility_delegate.h" |
| +#include "base/json/json_reader.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| +#include "chrome/browser/extensions/browsertest_util.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/extensions/extension_constants.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "extensions/browser/extension_host.h" |
| + |
| +void ChromeVoxBrowserTest::SetUpOnMainThread() { |
| + JavaScriptBrowserTest::SetUpOnMainThread(); |
| + |
| + chromevox_load_looper_ = new content::MessageLoopRunner(); |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| + content::NotificationService::AllSources()); |
| + |
| + chromeos::AccessibilityManager::Get()->EnableSpokenFeedback( |
| + true, ash::A11Y_NOTIFICATION_NONE); |
| + |
| + chromevox_load_looper_->Run(); |
|
dmazzoni
2014/06/09 06:59:45
Optional: it'd be nice to extract a helper class (
David Tseng
2014/06/10 05:35:21
Ok, done.
|
| +} |
| + |
| +bool ChromeVoxBrowserTest::RunJavascriptTestF(bool is_async, |
| + const std::string& test_fixture, |
| + const std::string& test_name) { |
| + ConstValueVector args; |
| + args.push_back(new base::StringValue(test_fixture)); |
| + args.push_back(new base::StringValue(test_name)); |
| + std::vector<base::string16> scripts; |
| + if (!libs_loaded_) { |
| + BuildJavascriptLibraries(&scripts); |
| + libs_loaded_ = true; |
| + } |
| + scripts.push_back(BuildRunTestJSCall(is_async, "RUN_TEST_F", args)); |
| + |
| + base::string16 script_16 = JoinString(scripts, '\n'); |
| + std::string script = base::UTF16ToUTF8(script_16); |
| + |
| + std::string result = |
| + extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
| + chromeos::AccessibilityManager::Get()->profile(), |
| + extension_misc::kChromeVoxExtensionId, |
| + script); |
| + |
| + base::JSONReader reader; |
| + scoped_ptr<base::Value> valueResult; |
|
dmazzoni
2014/06/09 06:59:45
Nit: value_result
David Tseng
2014/06/10 05:35:21
Done.
|
| + valueResult.reset(reader.Read(result)); |
| + CHECK_EQ(base::Value::TYPE_DICTIONARY, valueResult->GetType()); |
| + base::DictionaryValue* dictValue = |
|
dmazzoni
2014/06/09 06:59:45
same - switch to c++ naming style for locals in th
David Tseng
2014/06/10 05:35:21
Done.
|
| + static_cast<base::DictionaryValue*>(valueResult.get()); |
| + bool testResult; |
| + std::string testResultMessage; |
| + CHECK(dictValue->GetBoolean("result", &testResult)); |
| + CHECK(dictValue->GetString("message", &testResultMessage)); |
| + return testResult; |
| +} |
| + |
| +void ChromeVoxBrowserTest::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + switch (type) { |
| + case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
| + extensions::ExtensionHost* host = |
| + content::Details<extensions::ExtensionHost>(details).ptr(); |
| + if (host->extension_id() == extension_misc::kChromeVoxExtensionId) { |
| + chromevox_load_looper_->Quit(); |
| + } |
| + break; |
| + } |
| + } |
| +} |