OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "ash/shell.h" |
| 6 #include "base/strings/pattern.h" |
| 7 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 8 #include "chrome/browser/chromeos/accessibility/speech_monitor.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/browser_accessibility_state.h" |
| 15 #include "content/public/browser/notification_details.h" |
| 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/test/browser_test_utils.h" |
| 18 #include "extensions/browser/notification_types.h" |
| 19 #include "net/dns/mock_host_resolver.h" |
| 20 #include "ui/events/test/event_generator.h" |
| 21 #include "url/url_constants.h" |
| 22 |
| 23 namespace chromeos { |
| 24 |
| 25 class SelectToSpeakLiveSiteTest : public InProcessBrowserTest { |
| 26 protected: |
| 27 void SetUpOnMainThread() override { |
| 28 InProcessBrowserTest::SetUpOnMainThread(); |
| 29 |
| 30 ASSERT_FALSE(AccessibilityManager::Get()->IsSelectToSpeakEnabled()); |
| 31 |
| 32 content::WindowedNotificationObserver extension_load_waiter( |
| 33 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
| 34 content::NotificationService::AllSources()); |
| 35 AccessibilityManager::Get()->SetSelectToSpeakEnabled(true); |
| 36 extension_load_waiter.Wait(); |
| 37 |
| 38 aura::Window* root_window = ash::Shell::Get()->GetPrimaryRootWindow(); |
| 39 generator_.reset(new ui::test::EventGenerator(root_window)); |
| 40 |
| 41 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
| 42 } |
| 43 |
| 44 void SetUpInProcessBrowserTestFixture() override { |
| 45 // To avoid depending on external resources, browser tests don't allow |
| 46 // non-local DNS queries by default. Override this for this specific |
| 47 // manual test suite. |
| 48 scoped_refptr<net::RuleBasedHostResolverProc> resolver = |
| 49 new net::RuleBasedHostResolverProc(host_resolver()); |
| 50 resolver->AllowDirectLookup("*.google.com"); |
| 51 resolver->AllowDirectLookup("*.gstatic.com"); |
| 52 mock_host_resolver_override_.reset( |
| 53 new net::ScopedDefaultHostResolverProc(resolver.get())); |
| 54 } |
| 55 |
| 56 void TearDownInProcessBrowserTestFixture() override { |
| 57 mock_host_resolver_override_.reset(); |
| 58 } |
| 59 |
| 60 SpeechMonitor speech_monitor_; |
| 61 std::unique_ptr<ui::test::EventGenerator> generator_; |
| 62 |
| 63 std::unique_ptr<net::ScopedDefaultHostResolverProc> |
| 64 mock_host_resolver_override_; |
| 65 }; |
| 66 |
| 67 // This is a sanity check / integration test that Select-to-speak works |
| 68 // with Google Docs, since we have a small amount of code that works |
| 69 // around a compatibility issue. |
| 70 // |
| 71 // It's only run on an FYI bot because we don't want Docs outages to affect the |
| 72 // Chrome waterfall. |
| 73 // |
| 74 // To visually see what's happening while the test is running, |
| 75 // add this option: |
| 76 // --enable-pixel-output-in-tests |
| 77 IN_PROC_BROWSER_TEST_F(SelectToSpeakLiveSiteTest, GoogleDocsSupport) { |
| 78 const char* kGoogleDocsUrl = |
| 79 "https://docs.google.com/document/d/" |
| 80 "1qpu3koSIHpBzQbxeEE-dofSKXCIgdc4yJLI-o1LpCPs/view"; |
| 81 const char* kTextFoundInGoogleDoc = "Long-string-to-test-select-to-speak"; |
| 82 |
| 83 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| 84 |
| 85 ui_test_utils::NavigateToURL(browser(), GURL(kGoogleDocsUrl)); |
| 86 content::WebContents* web_contents = |
| 87 browser()->tab_strip_model()->GetActiveWebContents(); |
| 88 content::EnableAccessibilityForWebContents(web_contents); |
| 89 |
| 90 content::WaitForAccessibilityTreeToContainNodeWithName( |
| 91 web_contents, "Long-string-to-test-select-to-speak"); |
| 92 |
| 93 gfx::Rect bounds = browser()->window()->GetBounds(); |
| 94 generator_->PressKey(ui::VKEY_LWIN, 0 /* flags */); |
| 95 generator_->MoveMouseTo(bounds.x() + 8, bounds.y() + 200); |
| 96 generator_->PressLeftButton(); |
| 97 generator_->MoveMouseTo(bounds.x() + bounds.width() - 8, |
| 98 bounds.y() + bounds.height() - 8); |
| 99 generator_->ReleaseLeftButton(); |
| 100 generator_->ReleaseKey(ui::VKEY_LWIN, 0 /* flags */); |
| 101 |
| 102 for (;;) { |
| 103 std::string utterance = speech_monitor_.GetNextUtterance(); |
| 104 if (utterance == kTextFoundInGoogleDoc) |
| 105 break; |
| 106 } |
| 107 } |
| 108 |
| 109 } // namespace chromeos |
OLD | NEW |