OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <Cocoa/Cocoa.h> | 5 #include <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/scoped_nsobject.h" | 7 #include "base/scoped_nsobject.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
10 #include "chrome/browser/cocoa/status_bubble_mac.h" | 10 #include "chrome/browser/cocoa/status_bubble_mac.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #import "third_party/GTM/AppKit/GTMTheme.h" | |
14 | |
15 @interface StatusBubbleMacTestWindowDelegate : NSObject <GTMThemeDelegate>; | |
16 @end | |
17 @implementation StatusBubbleMacTestWindowDelegate | |
18 - (GTMTheme *)gtm_themeForWindow:(NSWindow *)window { | |
19 NSLog(@"gettheme"); | |
20 return [[[GTMTheme alloc] init] autorelease]; | |
21 } | |
22 @end | |
23 | 13 |
24 class StatusBubbleMacTest : public testing::Test { | 14 class StatusBubbleMacTest : public testing::Test { |
25 public: | 15 public: |
26 StatusBubbleMacTest() { | 16 StatusBubbleMacTest() { |
27 NSWindow* window = cocoa_helper_.window(); | 17 NSWindow* window = cocoa_helper_.window(); |
28 bubble_.reset(new StatusBubbleMac(window, nil)); | 18 bubble_.reset(new StatusBubbleMac(window, nil)); |
29 EXPECT_TRUE(bubble_.get()); | 19 EXPECT_TRUE(bubble_.get()); |
30 EXPECT_FALSE(bubble_->window_); // lazily creates window | 20 EXPECT_FALSE(bubble_->window_); // lazily creates window |
31 } | 21 } |
32 | 22 |
33 bool IsVisible() { | 23 bool IsVisible() { |
34 return [bubble_->window_ isVisible] ? true: false; | 24 return [bubble_->window_ isVisible] ? true: false; |
35 } | 25 } |
36 NSString* GetText() { | 26 NSString* GetText() { |
37 return bubble_->status_text_; | 27 return bubble_->status_text_; |
38 } | 28 } |
39 NSString* GetURLText() { | 29 NSString* GetURLText() { |
40 return bubble_->url_text_; | 30 return bubble_->url_text_; |
41 } | 31 } |
42 NSWindow* GetWindow() { | 32 |
43 return bubble_->window_; | |
44 } | |
45 NSWindow* GetParent() { | |
46 return bubble_->parent_; | |
47 } | |
48 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | 33 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... |
49 scoped_ptr<StatusBubbleMac> bubble_; | 34 scoped_ptr<StatusBubbleMac> bubble_; |
50 }; | 35 }; |
51 | 36 |
52 TEST_F(StatusBubbleMacTest, Theme) { | |
53 bubble_->SetStatus(L"Theme test"); // Creates the window | |
54 [GetParent() setDelegate: | |
55 [[[StatusBubbleMacTestWindowDelegate alloc] init] autorelease]]; | |
56 EXPECT_TRUE([GetParent() gtm_theme] != nil); | |
57 EXPECT_TRUE([[GetWindow() contentView] gtm_theme] != nil); | |
58 } | |
59 | |
60 TEST_F(StatusBubbleMacTest, SetStatus) { | 37 TEST_F(StatusBubbleMacTest, SetStatus) { |
61 bubble_->SetStatus(L""); | 38 bubble_->SetStatus(L""); |
62 bubble_->SetStatus(L"This is a test"); | 39 bubble_->SetStatus(L"This is a test"); |
63 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); | 40 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); |
64 EXPECT_TRUE(IsVisible()); | 41 EXPECT_TRUE(IsVisible()); |
65 | 42 |
66 // Set the status to the exact same thing again | 43 // Set the status to the exact same thing again |
67 bubble_->SetStatus(L"This is a test"); | 44 bubble_->SetStatus(L"This is a test"); |
68 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); | 45 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); |
69 | 46 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 NSWindow* window = cocoa_helper_.window(); | 88 NSWindow* window = cocoa_helper_.window(); |
112 // Create and delete immediately. | 89 // Create and delete immediately. |
113 StatusBubbleMac* bubble = new StatusBubbleMac(window, nil); | 90 StatusBubbleMac* bubble = new StatusBubbleMac(window, nil); |
114 delete bubble; | 91 delete bubble; |
115 | 92 |
116 // Create then delete while visible. | 93 // Create then delete while visible. |
117 bubble = new StatusBubbleMac(window, nil); | 94 bubble = new StatusBubbleMac(window, nil); |
118 bubble->SetStatus(L"showing"); | 95 bubble->SetStatus(L"showing"); |
119 delete bubble; | 96 delete bubble; |
120 } | 97 } |
OLD | NEW |