Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/resources/chromeos/chromevox/chromevox_browsertest.h" | |
| 6 | |
| 7 #include "ash/accessibility_delegate.h" | |
| 8 #include "base/json/json_reader.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chrome/browser/chrome_notification_types.h" | |
| 12 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
| 13 #include "chrome/browser/extensions/browsertest_util.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/common/extensions/extension_constants.h" | |
| 16 #include "content/public/browser/notification_service.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 18 #include "content/public/test/browser_test_utils.h" | |
| 19 #include "extensions/browser/extension_host.h" | |
| 20 | |
| 21 void ChromeVoxBrowserTest::SetUpOnMainThread() { | |
| 22 JavaScriptBrowserTest::SetUpOnMainThread(); | |
| 23 | |
| 24 chromevox_load_looper_ = new content::MessageLoopRunner(); | |
| 25 registrar_.Add(this, | |
| 26 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | |
| 27 content::NotificationService::AllSources()); | |
| 28 | |
| 29 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback( | |
| 30 true, ash::A11Y_NOTIFICATION_NONE); | |
| 31 | |
| 32 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.
| |
| 33 } | |
| 34 | |
| 35 bool ChromeVoxBrowserTest::RunJavascriptTestF(bool is_async, | |
| 36 const std::string& test_fixture, | |
| 37 const std::string& test_name) { | |
| 38 ConstValueVector args; | |
| 39 args.push_back(new base::StringValue(test_fixture)); | |
| 40 args.push_back(new base::StringValue(test_name)); | |
| 41 std::vector<base::string16> scripts; | |
| 42 if (!libs_loaded_) { | |
| 43 BuildJavascriptLibraries(&scripts); | |
| 44 libs_loaded_ = true; | |
| 45 } | |
| 46 scripts.push_back(BuildRunTestJSCall(is_async, "RUN_TEST_F", args)); | |
| 47 | |
| 48 base::string16 script_16 = JoinString(scripts, '\n'); | |
| 49 std::string script = base::UTF16ToUTF8(script_16); | |
| 50 | |
| 51 std::string result = | |
| 52 extensions::browsertest_util::ExecuteScriptInBackgroundPage( | |
| 53 chromeos::AccessibilityManager::Get()->profile(), | |
| 54 extension_misc::kChromeVoxExtensionId, | |
| 55 script); | |
| 56 | |
| 57 base::JSONReader reader; | |
| 58 scoped_ptr<base::Value> valueResult; | |
|
dmazzoni
2014/06/09 06:59:45
Nit: value_result
David Tseng
2014/06/10 05:35:21
Done.
| |
| 59 valueResult.reset(reader.Read(result)); | |
| 60 CHECK_EQ(base::Value::TYPE_DICTIONARY, valueResult->GetType()); | |
| 61 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.
| |
| 62 static_cast<base::DictionaryValue*>(valueResult.get()); | |
| 63 bool testResult; | |
| 64 std::string testResultMessage; | |
| 65 CHECK(dictValue->GetBoolean("result", &testResult)); | |
| 66 CHECK(dictValue->GetString("message", &testResultMessage)); | |
| 67 return testResult; | |
| 68 } | |
| 69 | |
| 70 void ChromeVoxBrowserTest::Observe( | |
| 71 int type, | |
| 72 const content::NotificationSource& source, | |
| 73 const content::NotificationDetails& details) { | |
| 74 switch (type) { | |
| 75 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | |
| 76 extensions::ExtensionHost* host = | |
| 77 content::Details<extensions::ExtensionHost>(details).ptr(); | |
| 78 if (host->extension_id() == extension_misc::kChromeVoxExtensionId) { | |
| 79 chromevox_load_looper_->Quit(); | |
| 80 } | |
| 81 break; | |
| 82 } | |
| 83 } | |
| 84 } | |
| OLD | NEW |