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