| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_nsobject.h" | 5 #include "base/scoped_nsobject.h" |
| 6 #include "chrome/browser/cocoa/browser_test_helper.h" | 6 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 7 #import "chrome/browser/cocoa/custom_home_pages_model.h" | 7 #import "chrome/browser/cocoa/custom_home_pages_model.h" |
| 8 #include "chrome/browser/session_startup_pref.h" | 8 #include "chrome/browser/session_startup_pref.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #import "testing/gtest_mac.h" |
| 10 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
| 11 | 12 |
| 12 // A helper for KVO and NSNotifications. Makes a note that it's been called | 13 // A helper for KVO and NSNotifications. Makes a note that it's been called |
| 13 // back. | 14 // back. |
| 14 @interface CustomHomePageHelper : NSObject { | 15 @interface CustomHomePageHelper : NSObject { |
| 15 @public | 16 @public |
| 16 BOOL sawNotification_; | 17 BOOL sawNotification_; |
| 17 } | 18 } |
| 18 @end | 19 @end |
| 19 | 20 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 126 |
| 126 // Cheat and insert NSString objects into the array. As long as we don't | 127 // Cheat and insert NSString objects into the array. As long as we don't |
| 127 // call -URLs, we'll be ok. | 128 // call -URLs, we'll be ok. |
| 128 [model_ insertObject:MakeEntry(@"www.google.com") inCustomHomePagesAtIndex:0]; | 129 [model_ insertObject:MakeEntry(@"www.google.com") inCustomHomePagesAtIndex:0]; |
| 129 EXPECT_TRUE(kvo_helper.get()->sawNotification_); | 130 EXPECT_TRUE(kvo_helper.get()->sawNotification_); |
| 130 [model_ insertObject:MakeEntry(@"www.yahoo.com") inCustomHomePagesAtIndex:1]; | 131 [model_ insertObject:MakeEntry(@"www.yahoo.com") inCustomHomePagesAtIndex:1]; |
| 131 [model_ insertObject:MakeEntry(@"dev.chromium.org") | 132 [model_ insertObject:MakeEntry(@"dev.chromium.org") |
| 132 inCustomHomePagesAtIndex:2]; | 133 inCustomHomePagesAtIndex:2]; |
| 133 EXPECT_EQ([model_ countOfCustomHomePages], 3U); | 134 EXPECT_EQ([model_ countOfCustomHomePages], 3U); |
| 134 | 135 |
| 135 EXPECT_TRUE([EntryURL([model_ objectInCustomHomePagesAtIndex:1]) | 136 EXPECT_NSEQ(@"http://www.yahoo.com/", |
| 136 isEqualToString:@"http://www.yahoo.com/"]); | 137 EntryURL([model_ objectInCustomHomePagesAtIndex:1])); |
| 137 | 138 |
| 138 kvo_helper.get()->sawNotification_ = NO; | 139 kvo_helper.get()->sawNotification_ = NO; |
| 139 [model_ removeObjectFromCustomHomePagesAtIndex:1]; | 140 [model_ removeObjectFromCustomHomePagesAtIndex:1]; |
| 140 EXPECT_TRUE(kvo_helper.get()->sawNotification_); | 141 EXPECT_TRUE(kvo_helper.get()->sawNotification_); |
| 141 EXPECT_EQ([model_ countOfCustomHomePages], 2U); | 142 EXPECT_EQ([model_ countOfCustomHomePages], 2U); |
| 142 EXPECT_TRUE([EntryURL([model_ objectInCustomHomePagesAtIndex:1]) | 143 EXPECT_NSEQ(@"http://dev.chromium.org/", |
| 143 isEqualToString:@"http://dev.chromium.org/"]); | 144 EntryURL([model_ objectInCustomHomePagesAtIndex:1])); |
| 144 EXPECT_TRUE([EntryURL([model_ objectInCustomHomePagesAtIndex:0]) | 145 EXPECT_NSEQ(@"http://www.google.com/", |
| 145 isEqualToString:@"http://www.google.com/"]); | 146 EntryURL([model_ objectInCustomHomePagesAtIndex:0])); |
| 146 | 147 |
| 147 [model_ removeObserver:kvo_helper forKeyPath:@"customHomePages"]; | 148 [model_ removeObserver:kvo_helper forKeyPath:@"customHomePages"]; |
| 148 } | 149 } |
| 149 | 150 |
| 150 // Test that when individual items are changed that they broadcast a message. | 151 // Test that when individual items are changed that they broadcast a message. |
| 151 TEST_F(CustomHomePagesModelTest, ModelChangedNotification) { | 152 TEST_F(CustomHomePagesModelTest, ModelChangedNotification) { |
| 152 scoped_nsobject<CustomHomePageHelper> kvo_helper( | 153 scoped_nsobject<CustomHomePageHelper> kvo_helper( |
| 153 [[CustomHomePageHelper alloc] init]); | 154 [[CustomHomePageHelper alloc] init]); |
| 154 [[NSNotificationCenter defaultCenter] | 155 [[NSNotificationCenter defaultCenter] |
| 155 addObserver:kvo_helper | 156 addObserver:kvo_helper |
| (...skipping 23 matching lines...) Expand all Loading... |
| 179 std::vector<GURL> urls; | 180 std::vector<GURL> urls; |
| 180 urls.push_back(GURL("http://www.google.com")); | 181 urls.push_back(GURL("http://www.google.com")); |
| 181 SessionStartupPref pref; | 182 SessionStartupPref pref; |
| 182 pref.urls = urls; | 183 pref.urls = urls; |
| 183 SessionStartupPref::SetStartupPref(helper_.profile(), pref); | 184 SessionStartupPref::SetStartupPref(helper_.profile(), pref); |
| 184 | 185 |
| 185 [model_ reloadURLs]; | 186 [model_ reloadURLs]; |
| 186 | 187 |
| 187 EXPECT_TRUE(kvo_helper.get()->sawNotification_); | 188 EXPECT_TRUE(kvo_helper.get()->sawNotification_); |
| 188 EXPECT_EQ([model_ countOfCustomHomePages], 1U); | 189 EXPECT_EQ([model_ countOfCustomHomePages], 1U); |
| 189 EXPECT_TRUE([EntryURL([model_ objectInCustomHomePagesAtIndex:0]) | 190 EXPECT_NSEQ(@"http://www.google.com/", |
| 190 isEqualToString:@"http://www.google.com/"]); | 191 EntryURL([model_ objectInCustomHomePagesAtIndex:0])); |
| 191 | 192 |
| 192 [model_ removeObserver:kvo_helper.get() forKeyPath:@"customHomePages"]; | 193 [model_ removeObserver:kvo_helper.get() forKeyPath:@"customHomePages"]; |
| 193 } | 194 } |
| 194 | 195 |
| 195 } // namespace | 196 } // namespace |
| OLD | NEW |