OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/scoped_nsobject.h" | 5 #include "base/memory/scoped_nsobject.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/prefs/public/pref_observer.h" | |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "chrome/browser/bookmarks/bookmark_utils.h" | 9 #include "chrome/browser/bookmarks/bookmark_utils.h" |
9 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 10 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
12 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #import "third_party/ocmock/gtest_support.h" | 17 #import "third_party/ocmock/gtest_support.h" |
17 #import "third_party/ocmock/ocmock/OCMock.h" | 18 #import "third_party/ocmock/ocmock/OCMock.h" |
18 | 19 |
19 // A BrowserWindowCocoa that goes PONG when | 20 // A BrowserWindowCocoa that goes PONG when |
20 // BOOKMARK_BAR_VISIBILITY_PREF_CHANGED is sent. This is so we can be | 21 // BOOKMARK_BAR_VISIBILITY_PREF_CHANGED is sent. This is so we can be |
21 // sure we are observing it. | 22 // sure we are observing it. |
22 class BrowserWindowCocoaPong : public BrowserWindowCocoa { | 23 class BrowserWindowCocoaPong : public BrowserWindowCocoa, public PrefObserver { |
23 public: | 24 public: |
24 BrowserWindowCocoaPong(Browser* browser, | 25 BrowserWindowCocoaPong(Browser* browser, |
25 BrowserWindowController* controller) | 26 BrowserWindowController* controller) |
26 : BrowserWindowCocoa(browser, controller) { | 27 : BrowserWindowCocoa(browser, controller) { |
27 pong_ = false; | 28 pong_ = false; |
28 } | 29 } |
29 virtual ~BrowserWindowCocoaPong() { } | 30 virtual ~BrowserWindowCocoaPong() { } |
30 | 31 |
31 void Observe(int type, | 32 virtual void OnPreferenceChanged(PrefServiceBase* service, |
32 const content::NotificationSource& source, | 33 const std::string& pref_name) OVERRIDE { |
33 const content::NotificationDetails& details) { | 34 if (pref_name == prefs::kShowBookmarkBar) |
34 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 35 pong_ = true; |
35 const std::string& pref_name = | |
36 *content::Details<std::string>(details).ptr(); | |
37 if (pref_name == prefs::kShowBookmarkBar) | |
38 pong_ = true; | |
39 } | |
40 BrowserWindowCocoa::Observe(type, source, details); | |
41 } | 36 } |
42 | 37 |
38 | |
Mattias Nissler (ping if slow)
2012/10/31 13:29:36
remove extra newline.
Jói
2012/10/31 14:56:26
Done.
| |
43 bool pong_; | 39 bool pong_; |
44 }; | 40 }; |
45 | 41 |
46 // Main test class. | 42 // Main test class. |
47 class BrowserWindowCocoaTest : public CocoaProfileTest { | 43 class BrowserWindowCocoaTest : public CocoaProfileTest { |
48 virtual void SetUp() { | 44 virtual void SetUp() { |
49 CocoaProfileTest::SetUp(); | 45 CocoaProfileTest::SetUp(); |
50 ASSERT_TRUE(browser()); | 46 ASSERT_TRUE(browser()); |
51 | 47 |
52 controller_ = [[BrowserWindowController alloc] initWithBrowser:browser() | 48 controller_ = [[BrowserWindowController alloc] initWithBrowser:browser() |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 [[[window_ stub] andReturn:nil] delegate]; | 238 [[[window_ stub] andReturn:nil] delegate]; |
243 [[[controller_ stub] andReturn:window_] window]; | 239 [[[controller_ stub] andReturn:window_] window]; |
244 [[window_ expect] orderOut:nil]; | 240 [[window_ expect] orderOut:nil]; |
245 [[window_ expect] close]; | 241 [[window_ expect] close]; |
246 CreateAndCloseBrowserWindow(); | 242 CreateAndCloseBrowserWindow(); |
247 EXPECT_OCMOCK_VERIFY(controller_); | 243 EXPECT_OCMOCK_VERIFY(controller_); |
248 EXPECT_OCMOCK_VERIFY(window_); | 244 EXPECT_OCMOCK_VERIFY(window_); |
249 } | 245 } |
250 | 246 |
251 // TODO(???): test other methods of BrowserWindowCocoa | 247 // TODO(???): test other methods of BrowserWindowCocoa |
OLD | NEW |