Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: extensions/browser/api/bluetooth/bluetooth_event_router_unittest.cc

Issue 544753003: Move BluetoothEventRouterTest to extensions_unittests suite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | extensions/browser/test_extensions_browser_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "chrome/browser/extensions/test_extension_system.h" 11 #include "content/public/browser/notification_service.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "content/public/test/test_browser_context.h"
13 #include "content/public/test/test_browser_thread.h" 13 #include "content/public/test/test_browser_thread.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "device/bluetooth/bluetooth_uuid.h" 14 #include "device/bluetooth/bluetooth_uuid.h"
16 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 15 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
17 #include "device/bluetooth/test/mock_bluetooth_device.h"
18 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" 16 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h"
19 #include "extensions/browser/event_router.h"
20 #include "extensions/browser/extension_registry.h" 17 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/extensions_test.h"
21 #include "extensions/common/api/bluetooth.h" 19 #include "extensions/common/api/bluetooth.h"
22 #include "extensions/common/extension_builder.h" 20 #include "extensions/common/extension_builder.h"
23 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
25 23
26 namespace { 24 namespace {
27 25
28 const char kTestExtensionId[] = "test extension id"; 26 const char kTestExtensionId[] = "test extension id";
29 const device::BluetoothUUID kAudioProfileUuid("1234"); 27 const device::BluetoothUUID kAudioProfileUuid("1234");
30 const device::BluetoothUUID kHealthProfileUuid("4321"); 28 const device::BluetoothUUID kHealthProfileUuid("4321");
31 29
32 } // namespace 30 } // namespace
33 31
34 namespace extensions { 32 namespace extensions {
35 33
36 namespace bluetooth = core_api::bluetooth; 34 namespace bluetooth = core_api::bluetooth;
37 35
38 class BluetoothEventRouterTest : public testing::Test { 36 class BluetoothEventRouterTest : public ExtensionsTest {
39 public: 37 public:
40 BluetoothEventRouterTest() 38 BluetoothEventRouterTest()
41 : ui_thread_(content::BrowserThread::UI, &message_loop_), 39 : ui_thread_(content::BrowserThread::UI, &message_loop_),
42 mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()), 40 mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()),
43 test_profile_(new TestingProfile()), 41 notification_service_(content::NotificationService::Create()),
44 router_(new BluetoothEventRouter(test_profile_.get())) { 42 router_(new BluetoothEventRouter(browser_context())) {
45 router_->SetAdapterForTest(mock_adapter_); 43 router_->SetAdapterForTest(mock_adapter_);
46 } 44 }
47 45
48 virtual void TearDown() OVERRIDE { 46 virtual void TearDown() OVERRIDE {
49 // Some profile-dependent services rely on UI thread to clean up. We make 47 // It's important to destroy the router before the browser context keyed
50 // sure they are properly cleaned up by running the UI message loop until 48 // services so it removes itself as an ExtensionRegistry observer.
51 // idle.
52 // It's important to destroy the router before the |test_profile_| so it
53 // removes itself as an observer.
54 router_.reset(NULL); 49 router_.reset(NULL);
55 test_profile_.reset(NULL); 50 ExtensionsTest::TearDown();
56 base::RunLoop run_loop;
57 run_loop.RunUntilIdle();
James Cook 2014/09/04 18:09:12 This appears unnecessary. I think it was there bec
58 } 51 }
59 52
60 protected: 53 protected:
61 base::MessageLoopForUI message_loop_; 54 base::MessageLoopForUI message_loop_;
62 // Note: |ui_thread_| must be declared before |router_|. 55 // Note: |ui_thread_| must be declared before |router_|.
63 content::TestBrowserThread ui_thread_; 56 content::TestBrowserThread ui_thread_;
64 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; 57 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_;
65 scoped_ptr<TestingProfile> test_profile_; 58 scoped_ptr<content::NotificationService> notification_service_;
66 scoped_ptr<BluetoothEventRouter> router_; 59 scoped_ptr<BluetoothEventRouter> router_;
67 }; 60 };
68 61
69 TEST_F(BluetoothEventRouterTest, BluetoothEventListener) { 62 TEST_F(BluetoothEventRouterTest, BluetoothEventListener) {
70 router_->OnListenerAdded(); 63 router_->OnListenerAdded();
71 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); 64 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
72 router_->OnListenerRemoved(); 65 router_->OnListenerRemoved();
73 } 66 }
74 67
75 TEST_F(BluetoothEventRouterTest, MultipleBluetoothEventListeners) { 68 TEST_F(BluetoothEventRouterTest, MultipleBluetoothEventListeners) {
76 router_->OnListenerAdded(); 69 router_->OnListenerAdded();
77 router_->OnListenerAdded(); 70 router_->OnListenerAdded();
78 router_->OnListenerAdded(); 71 router_->OnListenerAdded();
79 router_->OnListenerRemoved(); 72 router_->OnListenerRemoved();
80 router_->OnListenerRemoved(); 73 router_->OnListenerRemoved();
81 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); 74 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
82 router_->OnListenerRemoved(); 75 router_->OnListenerRemoved();
83 } 76 }
84 77
85 TEST_F(BluetoothEventRouterTest, UnloadExtension) { 78 TEST_F(BluetoothEventRouterTest, UnloadExtension) {
86 scoped_refptr<const extensions::Extension> extension = 79 scoped_refptr<const Extension> extension =
87 extensions::ExtensionBuilder() 80 ExtensionBuilder()
88 .SetManifest(extensions::DictionaryBuilder() 81 .SetManifest(DictionaryBuilder()
89 .Set("name", "BT event router test") 82 .Set("name", "BT event router test")
90 .Set("version", "1.0") 83 .Set("version", "1.0")
91 .Set("manifest_version", 2)) 84 .Set("manifest_version", 2))
92 .SetID(kTestExtensionId) 85 .SetID(kTestExtensionId)
93 .Build(); 86 .Build();
94 87
95 ExtensionRegistry::Get(test_profile_.get())->TriggerOnUnloaded( 88 ExtensionRegistry::Get(browser_context())->TriggerOnUnloaded(
96 extension.get(), UnloadedExtensionInfo::REASON_DISABLE); 89 extension.get(), UnloadedExtensionInfo::REASON_DISABLE);
97 90
98 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); 91 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
99 } 92 }
100 93
101 } // namespace extensions 94 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | extensions/browser/test_extensions_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698