| 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 |
| 13 | 23 |
| 14 class StatusBubbleMacTest : public testing::Test { | 24 class StatusBubbleMacTest : public testing::Test { |
| 15 public: | 25 public: |
| 16 StatusBubbleMacTest() { | 26 StatusBubbleMacTest() { |
| 17 NSWindow* window = cocoa_helper_.window(); | 27 NSWindow* window = cocoa_helper_.window(); |
| 18 bubble_.reset(new StatusBubbleMac(window, nil)); | 28 bubble_.reset(new StatusBubbleMac(window, nil)); |
| 19 EXPECT_TRUE(bubble_.get()); | 29 EXPECT_TRUE(bubble_.get()); |
| 20 EXPECT_FALSE(bubble_->window_); // lazily creates window | 30 EXPECT_FALSE(bubble_->window_); // lazily creates window |
| 21 } | 31 } |
| 22 | 32 |
| 23 bool IsVisible() { | 33 bool IsVisible() { |
| 24 return [bubble_->window_ isVisible] ? true: false; | 34 return [bubble_->window_ isVisible] ? true: false; |
| 25 } | 35 } |
| 26 NSString* GetText() { | 36 NSString* GetText() { |
| 27 return bubble_->status_text_; | 37 return bubble_->status_text_; |
| 28 } | 38 } |
| 29 NSString* GetURLText() { | 39 NSString* GetURLText() { |
| 30 return bubble_->url_text_; | 40 return bubble_->url_text_; |
| 31 } | 41 } |
| 32 | 42 NSWindow* GetWindow() { |
| 43 return bubble_->window_; |
| 44 } |
| 45 NSWindow* GetParent() { |
| 46 return bubble_->parent_; |
| 47 } |
| 33 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | 48 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... |
| 34 scoped_ptr<StatusBubbleMac> bubble_; | 49 scoped_ptr<StatusBubbleMac> bubble_; |
| 35 }; | 50 }; |
| 36 | 51 |
| 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 |
| 37 TEST_F(StatusBubbleMacTest, SetStatus) { | 60 TEST_F(StatusBubbleMacTest, SetStatus) { |
| 38 bubble_->SetStatus(L""); | 61 bubble_->SetStatus(L""); |
| 39 bubble_->SetStatus(L"This is a test"); | 62 bubble_->SetStatus(L"This is a test"); |
| 40 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); | 63 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); |
| 41 EXPECT_TRUE(IsVisible()); | 64 EXPECT_TRUE(IsVisible()); |
| 42 | 65 |
| 43 // Set the status to the exact same thing again | 66 // Set the status to the exact same thing again |
| 44 bubble_->SetStatus(L"This is a test"); | 67 bubble_->SetStatus(L"This is a test"); |
| 45 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); | 68 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); |
| 46 | 69 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 NSWindow* window = cocoa_helper_.window(); | 111 NSWindow* window = cocoa_helper_.window(); |
| 89 // Create and delete immediately. | 112 // Create and delete immediately. |
| 90 StatusBubbleMac* bubble = new StatusBubbleMac(window, nil); | 113 StatusBubbleMac* bubble = new StatusBubbleMac(window, nil); |
| 91 delete bubble; | 114 delete bubble; |
| 92 | 115 |
| 93 // Create then delete while visible. | 116 // Create then delete while visible. |
| 94 bubble = new StatusBubbleMac(window, nil); | 117 bubble = new StatusBubbleMac(window, nil); |
| 95 bubble->SetStatus(L"showing"); | 118 bubble->SetStatus(L"showing"); |
| 96 delete bubble; | 119 delete bubble; |
| 97 } | 120 } |
| OLD | NEW |