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 "base/files/file_path.h" | |
6 #include "base/path_service.h" | |
7 #include "base/prefs/pref_service.h" | |
8 #include "chrome/browser/extensions/component_loader.h" | |
9 #include "chrome/browser/extensions/error_console/error_console.h" | |
10 #include "chrome/browser/extensions/extension_browsertest.h" | |
11 #include "chrome/browser/extensions/extension_service.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/common/pref_names.h" | |
14 #include "chrome/test/base/ui_test_utils.h" | |
15 #include "extensions/common/extension.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 | |
18 | |
19 namespace extensions { | |
20 | |
21 class HotwordBrowserTest : public ExtensionBrowserTest { | |
22 public: | |
23 HotwordBrowserTest() : error_console_(NULL) { } | |
24 virtual ~HotwordBrowserTest() { } | |
25 | |
26 protected: | |
27 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
28 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); | |
29 | |
30 // We need a special flag to enable the hotword_helper extension. | |
31 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
32 "force-fieldtrials", "VoiceTrigger/Install/"); | |
asargent_no_longer_on_chrome
2014/09/24 19:19:59
nit: Are there constants either of these strings t
Anand Mistry (off Chromium)
2014/09/25 00:53:23
Yes for the first, no for the second.
| |
33 // Load the hotword_helper extension. | |
34 ComponentLoader::EnableBackgroundExtensionsForTesting(); | |
35 | |
36 // We need to enable the ErrorConsole FeatureSwitch in order to collect | |
37 // errors. This should be enabled on any channel <= Dev, but let's make | |
38 // sure (in case a test is running on, e.g., a beta channel). | |
39 FeatureSwitch::error_console()->SetOverrideValue( | |
40 FeatureSwitch::OVERRIDE_ENABLED); | |
41 } | |
42 | |
43 virtual void SetUpOnMainThread() OVERRIDE { | |
44 ExtensionBrowserTest::SetUpOnMainThread(); | |
45 | |
46 // Errors are only kept if we have Developer Mode enabled. | |
47 profile()->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true); | |
48 | |
49 error_console_ = ErrorConsole::Get(profile()); | |
50 ASSERT_TRUE(error_console_); | |
51 } | |
52 | |
53 void RunMessageLoopForMs(int ms) { | |
54 base::MessageLoop::current()->PostDelayedTask( | |
55 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | |
56 base::TimeDelta::FromMilliseconds(ms)); | |
57 content::RunMessageLoop(); | |
58 } | |
59 | |
60 ErrorConsole* error_console() { return error_console_; } | |
61 | |
62 private: | |
63 // Weak reference to the ErrorConsole. | |
64 ErrorConsole* error_console_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(HotwordBrowserTest); | |
67 }; | |
68 | |
69 // Test we silently capture an exception from a message handler's response | |
70 // callback. This happens when the caller to chrome.runtime.sendMessage() | |
71 // doesn't specify a response callback. | |
72 IN_PROC_BROWSER_TEST_F(HotwordBrowserTest, MessageSendResponseError) { | |
73 // Enable error reporting for the hotword helper extension. | |
74 error_console()->SetReportingAllForExtension( | |
75 "dnhpdliibojhegemfjheidglijccjfmc", | |
76 true); | |
77 | |
78 const Extension* extension = extension_service()->GetExtensionById( | |
79 "dnhpdliibojhegemfjheidglijccjfmc", false); | |
asargent_no_longer_on_chrome
2014/09/24 19:19:59
nit: use a constant to avoid the id string duplica
Anand Mistry (off Chromium)
2014/09/25 00:53:23
Done.
| |
80 ASSERT_TRUE(extension); | |
81 const Extension* test_extension = LoadExtension( | |
82 test_data_dir_.AppendASCII("hotword")); | |
83 ASSERT_TRUE(test_extension); | |
84 | |
85 // We're testing that an error doesn't happen. Since there's no event we can | |
86 // wait for, just sleep for a bit and check. | |
87 RunMessageLoopForMs(200); | |
asargent_no_longer_on_chrome
2014/09/24 19:19:59
In the past doing this sort of "sleep for a fixed
Anand Mistry (off Chromium)
2014/09/25 00:53:23
Done.
| |
88 | |
89 ASSERT_TRUE(error_console()->GetErrorsForExtension(extension->id()).empty()); | |
90 } | |
91 | |
92 } // namespace extensions | |
OLD | NEW |