| 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 "base/scoped_nsautorelease_pool.h" | 5 #include "base/mac/scoped_nsautorelease_pool.h" |
| 6 #include "base/scoped_nsobject.h" | 6 #include "base/scoped_nsobject.h" |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/cocoa/browser_test_helper.h" | 8 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 9 #include "chrome/browser/cocoa/cocoa_test_helper.h" | 9 #include "chrome/browser/cocoa/cocoa_test_helper.h" |
| 10 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" | 10 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" |
| 11 #include "chrome/browser/search_engines/template_url.h" | 11 #include "chrome/browser/search_engines/template_url.h" |
| 12 #include "chrome/browser/search_engines/template_url_model.h" | 12 #include "chrome/browser/search_engines/template_url_model.h" |
| 13 #include "chrome/test/testing_profile.h" | 13 #include "chrome/test/testing_profile.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // window's delegate so that the controller can clean itself up in | 64 // window's delegate so that the controller can clean itself up in |
| 65 // |-windowWillClose:|. | 65 // |-windowWillClose:|. |
| 66 ASSERT_TRUE([controller_ window]); | 66 ASSERT_TRUE([controller_ window]); |
| 67 | 67 |
| 68 [controller_ close]; | 68 [controller_ close]; |
| 69 CocoaTest::TearDown(); | 69 CocoaTest::TearDown(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Helper to count the keyword editors. | 72 // Helper to count the keyword editors. |
| 73 NSUInteger CountKeywordEditors() { | 73 NSUInteger CountKeywordEditors() { |
| 74 base::ScopedNSAutoreleasePool pool; | 74 base::mac::ScopedNSAutoreleasePool pool; |
| 75 NSUInteger count = 0; | 75 NSUInteger count = 0; |
| 76 for (NSWindow* window in [NSApp windows]) { | 76 for (NSWindow* window in [NSApp windows]) { |
| 77 id controller = [window windowController]; | 77 id controller = [window windowController]; |
| 78 if ([controller isKindOfClass:[KeywordEditorCocoaController class]]) { | 78 if ([controller isKindOfClass:[KeywordEditorCocoaController class]]) { |
| 79 ++count; | 79 ++count; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 return count; | 82 return count; |
| 83 } | 83 } |
| 84 | 84 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 KeywordEditorCocoaController* sharedInstance = | 101 KeywordEditorCocoaController* sharedInstance = |
| 102 [KeywordEditorCocoaController sharedInstanceForProfile:profile]; | 102 [KeywordEditorCocoaController sharedInstanceForProfile:profile]; |
| 103 EXPECT_TRUE(nil == sharedInstance); | 103 EXPECT_TRUE(nil == sharedInstance); |
| 104 EXPECT_EQ(CountKeywordEditors(), 0U); | 104 EXPECT_EQ(CountKeywordEditors(), 0U); |
| 105 | 105 |
| 106 const NSUInteger initial_window_count([[NSApp windows] count]); | 106 const NSUInteger initial_window_count([[NSApp windows] count]); |
| 107 | 107 |
| 108 // The window unwinds using -autorelease, so we need to introduce an | 108 // The window unwinds using -autorelease, so we need to introduce an |
| 109 // autorelease pool to really test whether it went away or not. | 109 // autorelease pool to really test whether it went away or not. |
| 110 { | 110 { |
| 111 base::ScopedNSAutoreleasePool pool; | 111 base::mac::ScopedNSAutoreleasePool pool; |
| 112 | 112 |
| 113 // +showKeywordEditor: creates a new controller. | 113 // +showKeywordEditor: creates a new controller. |
| 114 [KeywordEditorCocoaController showKeywordEditor:profile]; | 114 [KeywordEditorCocoaController showKeywordEditor:profile]; |
| 115 sharedInstance = | 115 sharedInstance = |
| 116 [KeywordEditorCocoaController sharedInstanceForProfile:profile]; | 116 [KeywordEditorCocoaController sharedInstanceForProfile:profile]; |
| 117 EXPECT_TRUE(sharedInstance); | 117 EXPECT_TRUE(sharedInstance); |
| 118 EXPECT_EQ(CountKeywordEditors(), 1U); | 118 EXPECT_EQ(CountKeywordEditors(), 1U); |
| 119 | 119 |
| 120 // Another call doesn't create another controller. | 120 // Another call doesn't create another controller. |
| 121 [KeywordEditorCocoaController showKeywordEditor:profile]; | 121 [KeywordEditorCocoaController showKeywordEditor:profile]; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ASSERT_TRUE([controller_ tableView:table isGroupRow:0]); | 218 ASSERT_TRUE([controller_ tableView:table isGroupRow:0]); |
| 219 ASSERT_FALSE([controller_ tableView:table isGroupRow:1]); | 219 ASSERT_FALSE([controller_ tableView:table isGroupRow:1]); |
| 220 ASSERT_FALSE([controller_ tableView:table isGroupRow:2]); | 220 ASSERT_FALSE([controller_ tableView:table isGroupRow:2]); |
| 221 | 221 |
| 222 ASSERT_FALSE([controller_ tableView:table shouldSelectRow:0]); | 222 ASSERT_FALSE([controller_ tableView:table shouldSelectRow:0]); |
| 223 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:1]); | 223 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:1]); |
| 224 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:2]); | 224 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:2]); |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace | 227 } // namespace |
| OLD | NEW |