| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "app/tree_model.h" | 8 #include "app/tree_model.h" |
| 9 #import "base/scoped_nsobject.h" | 9 #import "base/scoped_nsobject.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "chrome/browser/cocoa/browser_test_helper.h" | 11 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 12 #include "chrome/browser/browsing_data_remover.h" | 12 #include "chrome/browser/browsing_data_remover.h" |
| 13 #include "chrome/browser/cocoa/clear_browsing_data_controller.h" | 13 #include "chrome/browser/cocoa/clear_browsing_data_controller.h" |
| 14 #import "chrome/browser/cocoa/cookies_window_controller.h" | 14 #import "chrome/browser/cocoa/cookies_window_controller.h" |
| 15 #include "chrome/browser/cocoa/cocoa_test_helper.h" | 15 #include "chrome/browser/cocoa/cocoa_test_helper.h" |
| 16 #include "chrome/browser/mock_browsing_data_database_helper.h" | 16 #include "chrome/browser/mock_browsing_data_database_helper.h" |
| 17 #include "chrome/browser/mock_browsing_data_local_storage_helper.h" | 17 #include "chrome/browser/mock_browsing_data_local_storage_helper.h" |
| 18 #include "chrome/browser/mock_browsing_data_appcache_helper.h" | 18 #include "chrome/browser/mock_browsing_data_appcache_helper.h" |
| 19 #include "chrome/browser/cookies_tree_model.h" | 19 #include "chrome/browser/cookies_tree_model.h" |
| 20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 21 #include "chrome/common/net/url_request_context_getter.h" | 21 #include "chrome/common/net/url_request_context_getter.h" |
| 22 #include "chrome/test/testing_profile.h" | 22 #include "chrome/test/testing_profile.h" |
| 23 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 25 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #import "testing/gtest_mac.h" |
| 27 #include "testing/platform_test.h" | 28 #include "testing/platform_test.h" |
| 28 #import "third_party/ocmock/OCMock/OCMock.h" | 29 #import "third_party/ocmock/OCMock/OCMock.h" |
| 29 | 30 |
| 30 // Used to test FindCocoaNode. This only sets the title and node, without | 31 // Used to test FindCocoaNode. This only sets the title and node, without |
| 31 // initializing any other members. | 32 // initializing any other members. |
| 32 @interface FakeCocoaCookieTreeNode : CocoaCookieTreeNode { | 33 @interface FakeCocoaCookieTreeNode : CocoaCookieTreeNode { |
| 33 TreeModelNode* testNode_; | 34 TreeModelNode* testNode_; |
| 34 } | 35 } |
| 35 - (id)initWithTreeNode:(TreeModelNode*)node; | 36 - (id)initWithTreeNode:(TreeModelNode*)node; |
| 36 @end | 37 @end |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeCookie) { | 138 TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeCookie) { |
| 138 net::CookieMonster* cm = browser_helper_.profile()->GetCookieMonster(); | 139 net::CookieMonster* cm = browser_helper_.profile()->GetCookieMonster(); |
| 139 cm->SetCookie(GURL("http://foo.com"), "A=B"); | 140 cm->SetCookie(GURL("http://foo.com"), "A=B"); |
| 140 CookiesTreeModel model(cm, database_helper_, local_storage_helper_, nil); | 141 CookiesTreeModel model(cm, database_helper_, local_storage_helper_, nil); |
| 141 | 142 |
| 142 // Root --> foo.com --> Cookies --> A. Create node for 'A'. | 143 // Root --> foo.com --> Cookies --> A. Create node for 'A'. |
| 143 TreeModelNode* node = model.GetRoot()->GetChild(0)->GetChild(0)->GetChild(0); | 144 TreeModelNode* node = model.GetRoot()->GetChild(0)->GetChild(0)->GetChild(0); |
| 144 CocoaCookieTreeNode* cookie = CocoaNodeFromTreeNode(node); | 145 CocoaCookieTreeNode* cookie = CocoaNodeFromTreeNode(node); |
| 145 | 146 |
| 146 CocoaCookieDetails* details = [cookie details]; | 147 CocoaCookieDetails* details = [cookie details]; |
| 147 EXPECT_TRUE([@"B" isEqualToString:[details content]]); | 148 EXPECT_NSEQ(@"B", [details content]); |
| 148 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_COOKIE_EXPIRES_SESSION) | 149 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_COOKIE_EXPIRES_SESSION), |
| 149 isEqualToString:[details expires]]); | 150 [details expires]); |
| 150 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_COOKIE_SENDFOR_ANY) | 151 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_COOKIE_SENDFOR_ANY), |
| 151 isEqualToString:[details sendFor]]); | 152 [details sendFor]); |
| 152 EXPECT_TRUE([@"A" isEqualToString:[cookie title]]); | 153 EXPECT_NSEQ(@"A", [cookie title]); |
| 153 EXPECT_TRUE([@"A" isEqualToString:[details name]]); | 154 EXPECT_NSEQ(@"A", [details name]); |
| 154 EXPECT_TRUE([@"/" isEqualToString:[details path]]); | 155 EXPECT_NSEQ(@"/", [details path]); |
| 155 EXPECT_EQ(0U, [[cookie children] count]); | 156 EXPECT_EQ(0U, [[cookie children] count]); |
| 156 EXPECT_TRUE([details created]); | 157 EXPECT_TRUE([details created]); |
| 157 EXPECT_TRUE([cookie isLeaf]); | 158 EXPECT_TRUE([cookie isLeaf]); |
| 158 EXPECT_EQ(node, [cookie treeNode]); | 159 EXPECT_EQ(node, [cookie treeNode]); |
| 159 } | 160 } |
| 160 | 161 |
| 161 TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeRecursive) { | 162 TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeRecursive) { |
| 162 net::CookieMonster* cm = browser_helper_.profile()->GetCookieMonster(); | 163 net::CookieMonster* cm = browser_helper_.profile()->GetCookieMonster(); |
| 163 cm->SetCookie(GURL("http://foo.com"), "A=B"); | 164 cm->SetCookie(GURL("http://foo.com"), "A=B"); |
| 164 CookiesTreeModel model(cm, database_helper_, local_storage_helper_, nil); | 165 CookiesTreeModel model(cm, database_helper_, local_storage_helper_, nil); |
| 165 | 166 |
| 166 // Root --> foo.com --> Cookies --> A. Create node for 'foo.com'. | 167 // Root --> foo.com --> Cookies --> A. Create node for 'foo.com'. |
| 167 CookieTreeNode* node = model.GetRoot()->GetChild(0); | 168 CookieTreeNode* node = model.GetRoot()->GetChild(0); |
| 168 CocoaCookieTreeNode* domain = CocoaNodeFromTreeNode(node); | 169 CocoaCookieTreeNode* domain = CocoaNodeFromTreeNode(node); |
| 169 CocoaCookieTreeNode* cookies = [[domain children] objectAtIndex:0]; | 170 CocoaCookieTreeNode* cookies = [[domain children] objectAtIndex:0]; |
| 170 CocoaCookieTreeNode* cookie = [[cookies children] objectAtIndex:0]; | 171 CocoaCookieTreeNode* cookie = [[cookies children] objectAtIndex:0]; |
| 171 | 172 |
| 172 // Test domain-level node. | 173 // Test domain-level node. |
| 173 EXPECT_TRUE([@"foo.com" isEqualToString:[domain title]]); | 174 EXPECT_NSEQ(@"foo.com", [domain title]); |
| 174 | 175 |
| 175 EXPECT_FALSE([domain isLeaf]); | 176 EXPECT_FALSE([domain isLeaf]); |
| 176 EXPECT_EQ(1U, [[domain children] count]); | 177 EXPECT_EQ(1U, [[domain children] count]); |
| 177 EXPECT_EQ(node, [domain treeNode]); | 178 EXPECT_EQ(node, [domain treeNode]); |
| 178 | 179 |
| 179 // Test "Cookies" folder node. | 180 // Test "Cookies" folder node. |
| 180 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_COOKIES) isEqualToString: | 181 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_COOKIES), [cookies title]); |
| 181 [cookies title]]); | |
| 182 EXPECT_FALSE([cookies isLeaf]); | 182 EXPECT_FALSE([cookies isLeaf]); |
| 183 EXPECT_EQ(1U, [[cookies children] count]); | 183 EXPECT_EQ(1U, [[cookies children] count]); |
| 184 EXPECT_EQ(node->GetChild(0), [cookies treeNode]); | 184 EXPECT_EQ(node->GetChild(0), [cookies treeNode]); |
| 185 | 185 |
| 186 // Test cookie node. This is the same as CocoaNodeFromTreeNodeCookie. | 186 // Test cookie node. This is the same as CocoaNodeFromTreeNodeCookie. |
| 187 CocoaCookieDetails* details = [cookie details]; | 187 CocoaCookieDetails* details = [cookie details]; |
| 188 EXPECT_TRUE([@"B" isEqualToString:[details content]]); | 188 EXPECT_NSEQ(@"B", [details content]); |
| 189 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_COOKIE_EXPIRES_SESSION) | 189 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_COOKIE_EXPIRES_SESSION), |
| 190 isEqualToString:[details expires]]); | 190 [details expires]); |
| 191 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_COOKIE_SENDFOR_ANY) | 191 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_COOKIE_SENDFOR_ANY), |
| 192 isEqualToString:[details sendFor]]); | 192 [details sendFor]); |
| 193 EXPECT_TRUE([@"A" isEqualToString:[cookie title]]); | 193 EXPECT_NSEQ(@"A", [cookie title]); |
| 194 EXPECT_TRUE([@"A" isEqualToString:[details name]]); | 194 EXPECT_NSEQ(@"A", [details name]); |
| 195 EXPECT_TRUE([@"/" isEqualToString:[details path]]); | 195 EXPECT_NSEQ(@"/", [details path]); |
| 196 EXPECT_TRUE([@"foo.com" isEqualToString:[details domain]]); | 196 EXPECT_NSEQ(@"foo.com", [details domain]); |
| 197 EXPECT_EQ(0U, [[cookie children] count]); | 197 EXPECT_EQ(0U, [[cookie children] count]); |
| 198 EXPECT_TRUE([details created]); | 198 EXPECT_TRUE([details created]); |
| 199 EXPECT_TRUE([cookie isLeaf]); | 199 EXPECT_TRUE([cookie isLeaf]); |
| 200 EXPECT_EQ(node->GetChild(0)->GetChild(0), [cookie treeNode]); | 200 EXPECT_EQ(node->GetChild(0)->GetChild(0), [cookie treeNode]); |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST_F(CookiesWindowControllerTest, TreeNodesAdded) { | 203 TEST_F(CookiesWindowControllerTest, TreeNodesAdded) { |
| 204 const GURL url = GURL("http://foo.com"); | 204 const GURL url = GURL("http://foo.com"); |
| 205 TestingProfile* profile = browser_helper_.profile(); | 205 TestingProfile* profile = browser_helper_.profile(); |
| 206 net::CookieMonster* cm = profile->GetCookieMonster(); | 206 net::CookieMonster* cm = profile->GetCookieMonster(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 CookiesTreeModel* model = [controller_ treeModel]; | 265 CookiesTreeModel* model = [controller_ treeModel]; |
| 266 // Root --> foo.com --> Cookies. | 266 // Root --> foo.com --> Cookies. |
| 267 CookieTreeNode* parent = model->GetRoot()->GetChild(0)->GetChild(0); | 267 CookieTreeNode* parent = model->GetRoot()->GetChild(0)->GetChild(0); |
| 268 | 268 |
| 269 // Pretend to remove the nodes. | 269 // Pretend to remove the nodes. |
| 270 [controller_ modelObserver]->TreeNodesRemoved(model, parent, 1, 2); | 270 [controller_ modelObserver]->TreeNodesRemoved(model, parent, 1, 2); |
| 271 | 271 |
| 272 EXPECT_EQ(1U, [cocoa_children count]); | 272 EXPECT_EQ(1U, [cocoa_children count]); |
| 273 | 273 |
| 274 NSString* title = [[[cocoa_children objectAtIndex:0] details] name]; | 274 NSString* title = [[[cocoa_children objectAtIndex:0] details] name]; |
| 275 EXPECT_TRUE([@"A" isEqualToString:title]); | 275 EXPECT_NSEQ(@"A", title); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_F(CookiesWindowControllerTest, TreeNodeChildrenReordered) { | 278 TEST_F(CookiesWindowControllerTest, TreeNodeChildrenReordered) { |
| 279 const GURL url = GURL("http://foo.com"); | 279 const GURL url = GURL("http://foo.com"); |
| 280 TestingProfile* profile = browser_helper_.profile(); | 280 TestingProfile* profile = browser_helper_.profile(); |
| 281 net::CookieMonster* cm = profile->GetCookieMonster(); | 281 net::CookieMonster* cm = profile->GetCookieMonster(); |
| 282 cm->SetCookie(url, "A=B"); | 282 cm->SetCookie(url, "A=B"); |
| 283 cm->SetCookie(url, "C=D"); | 283 cm->SetCookie(url, "C=D"); |
| 284 cm->SetCookie(url, "E=F"); | 284 cm->SetCookie(url, "E=F"); |
| 285 | 285 |
| 286 controller_.reset( | 286 controller_.reset( |
| 287 [[CookiesWindowController alloc] initWithProfile:profile | 287 [[CookiesWindowController alloc] initWithProfile:profile |
| 288 databaseHelper:database_helper_ | 288 databaseHelper:database_helper_ |
| 289 storageHelper:local_storage_helper_ | 289 storageHelper:local_storage_helper_ |
| 290 appcacheHelper:appcache_helper_]); | 290 appcacheHelper:appcache_helper_]); |
| 291 | 291 |
| 292 // Root --> foo.com --> Cookies. | 292 // Root --> foo.com --> Cookies. |
| 293 NSMutableArray* cocoa_children = | 293 NSMutableArray* cocoa_children = |
| 294 [[[[[[controller_ cocoaTreeModel] children] objectAtIndex:0] | 294 [[[[[[controller_ cocoaTreeModel] children] objectAtIndex:0] |
| 295 children] objectAtIndex:0] mutableChildren]; | 295 children] objectAtIndex:0] mutableChildren]; |
| 296 EXPECT_EQ(3U, [cocoa_children count]); | 296 EXPECT_EQ(3U, [cocoa_children count]); |
| 297 | 297 |
| 298 // Check default ordering. | 298 // Check default ordering. |
| 299 CocoaCookieTreeNode* node = [cocoa_children objectAtIndex:0]; | 299 CocoaCookieTreeNode* node = [cocoa_children objectAtIndex:0]; |
| 300 EXPECT_TRUE([@"A" isEqualToString:[[node details] name]]); | 300 EXPECT_NSEQ(@"A", [[node details] name]); |
| 301 node = [cocoa_children objectAtIndex:1]; | 301 node = [cocoa_children objectAtIndex:1]; |
| 302 EXPECT_TRUE([@"C" isEqualToString:[[node details] name]]); | 302 EXPECT_NSEQ(@"C", [[node details] name]); |
| 303 node = [cocoa_children objectAtIndex:2]; | 303 node = [cocoa_children objectAtIndex:2]; |
| 304 EXPECT_TRUE([@"E" isEqualToString:[[node details] name]]); | 304 EXPECT_NSEQ(@"E", [[node details] name]); |
| 305 | 305 |
| 306 CookiesTreeModel* model = [controller_ treeModel]; | 306 CookiesTreeModel* model = [controller_ treeModel]; |
| 307 // Root --> foo.com --> Cookies. | 307 // Root --> foo.com --> Cookies. |
| 308 CookieTreeNode* parent = model->GetRoot()->GetChild(0)->GetChild(0); | 308 CookieTreeNode* parent = model->GetRoot()->GetChild(0)->GetChild(0); |
| 309 | 309 |
| 310 // Reorder the nodes. | 310 // Reorder the nodes. |
| 311 CookieTreeNode* node_e = parent->Remove(2); | 311 CookieTreeNode* node_e = parent->Remove(2); |
| 312 CookieTreeNode* node_c = parent->Remove(1); | 312 CookieTreeNode* node_c = parent->Remove(1); |
| 313 parent->Add(0, node_e); | 313 parent->Add(0, node_e); |
| 314 parent->Add(2, node_c); | 314 parent->Add(2, node_c); |
| 315 | 315 |
| 316 // Notify the observer of the reordering. | 316 // Notify the observer of the reordering. |
| 317 [controller_ modelObserver]->TreeNodeChildrenReordered(model, parent); | 317 [controller_ modelObserver]->TreeNodeChildrenReordered(model, parent); |
| 318 | 318 |
| 319 // Check the new order. | 319 // Check the new order. |
| 320 node = [cocoa_children objectAtIndex:0]; | 320 node = [cocoa_children objectAtIndex:0]; |
| 321 EXPECT_TRUE([@"E" isEqualToString:[[node details] name]]); | 321 EXPECT_NSEQ(@"E", [[node details] name]); |
| 322 node = [cocoa_children objectAtIndex:1]; | 322 node = [cocoa_children objectAtIndex:1]; |
| 323 EXPECT_TRUE([@"A" isEqualToString:[[node details] name]]); | 323 EXPECT_NSEQ(@"A", [[node details] name]); |
| 324 node = [cocoa_children objectAtIndex:2]; | 324 node = [cocoa_children objectAtIndex:2]; |
| 325 EXPECT_TRUE([@"C" isEqualToString:[[node details] name]]); | 325 EXPECT_NSEQ(@"C", [[node details] name]); |
| 326 } | 326 } |
| 327 | 327 |
| 328 TEST_F(CookiesWindowControllerTest, TreeNodeChanged) { | 328 TEST_F(CookiesWindowControllerTest, TreeNodeChanged) { |
| 329 const GURL url = GURL("http://foo.com"); | 329 const GURL url = GURL("http://foo.com"); |
| 330 TestingProfile* profile = browser_helper_.profile(); | 330 TestingProfile* profile = browser_helper_.profile(); |
| 331 net::CookieMonster* cm = profile->GetCookieMonster(); | 331 net::CookieMonster* cm = profile->GetCookieMonster(); |
| 332 cm->SetCookie(url, "A=B"); | 332 cm->SetCookie(url, "A=B"); |
| 333 | 333 |
| 334 controller_.reset( | 334 controller_.reset( |
| 335 [[CookiesWindowController alloc] initWithProfile:profile | 335 [[CookiesWindowController alloc] initWithProfile:profile |
| 336 databaseHelper:database_helper_ | 336 databaseHelper:database_helper_ |
| 337 storageHelper:local_storage_helper_ | 337 storageHelper:local_storage_helper_ |
| 338 appcacheHelper:appcache_helper_]); | 338 appcacheHelper:appcache_helper_]); |
| 339 | 339 |
| 340 CookiesTreeModel* model = [controller_ treeModel]; | 340 CookiesTreeModel* model = [controller_ treeModel]; |
| 341 // Root --> foo.com --> Cookies. | 341 // Root --> foo.com --> Cookies. |
| 342 CookieTreeNode* node = model->GetRoot()->GetChild(0)->GetChild(0); | 342 CookieTreeNode* node = model->GetRoot()->GetChild(0)->GetChild(0); |
| 343 | 343 |
| 344 // Root --> foo.com --> Cookies. | 344 // Root --> foo.com --> Cookies. |
| 345 CocoaCookieTreeNode* cocoa_node = | 345 CocoaCookieTreeNode* cocoa_node = |
| 346 [[[[[controller_ cocoaTreeModel] children] objectAtIndex:0] | 346 [[[[[controller_ cocoaTreeModel] children] objectAtIndex:0] |
| 347 children] objectAtIndex:0]; | 347 children] objectAtIndex:0]; |
| 348 | 348 |
| 349 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_COOKIES) isEqualToString: | 349 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_COOKIES), |
| 350 [cocoa_node title]]); | 350 [cocoa_node title]); |
| 351 | 351 |
| 352 // Fake update the cookie folder's title. This would never happen in reality, | 352 // Fake update the cookie folder's title. This would never happen in reality, |
| 353 // but it tests the code path that ultimately calls CocoaNodeFromTreeNode, | 353 // but it tests the code path that ultimately calls CocoaNodeFromTreeNode, |
| 354 // which is tested elsewhere. | 354 // which is tested elsewhere. |
| 355 node->SetTitle(L"Silly Change"); | 355 node->SetTitle(L"Silly Change"); |
| 356 [controller_ modelObserver]->TreeNodeChanged(model, node); | 356 [controller_ modelObserver]->TreeNodeChanged(model, node); |
| 357 | 357 |
| 358 EXPECT_TRUE([@"Silly Change" isEqualToString:[cocoa_node title]]); | 358 EXPECT_NSEQ(@"Silly Change", [cocoa_node title]); |
| 359 } | 359 } |
| 360 | 360 |
| 361 TEST_F(CookiesWindowControllerTest, DeleteCookie) { | 361 TEST_F(CookiesWindowControllerTest, DeleteCookie) { |
| 362 const GURL url = GURL("http://foo.com"); | 362 const GURL url = GURL("http://foo.com"); |
| 363 TestingProfile* profile = browser_helper_.profile(); | 363 TestingProfile* profile = browser_helper_.profile(); |
| 364 net::CookieMonster* cm = profile->GetCookieMonster(); | 364 net::CookieMonster* cm = profile->GetCookieMonster(); |
| 365 cm->SetCookie(url, "A=B"); | 365 cm->SetCookie(url, "A=B"); |
| 366 cm->SetCookie(url, "C=D"); | 366 cm->SetCookie(url, "C=D"); |
| 367 cm->SetCookie(GURL("http://google.com"), "E=F"); | 367 cm->SetCookie(GURL("http://google.com"), "E=F"); |
| 368 | 368 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 381 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:pathA length:3]; | 381 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:pathA length:3]; |
| 382 [treeController setSelectionIndexPath:indexPath]; | 382 [treeController setSelectionIndexPath:indexPath]; |
| 383 | 383 |
| 384 // Press the "Delete" button. | 384 // Press the "Delete" button. |
| 385 [controller deleteCookie:nil]; | 385 [controller deleteCookie:nil]; |
| 386 | 386 |
| 387 // Root --> foo.com --> Cookies. | 387 // Root --> foo.com --> Cookies. |
| 388 NSArray* cookies = [[[[[[controller cocoaTreeModel] children] | 388 NSArray* cookies = [[[[[[controller cocoaTreeModel] children] |
| 389 objectAtIndex:0] children] objectAtIndex:0] children]; | 389 objectAtIndex:0] children] objectAtIndex:0] children]; |
| 390 EXPECT_EQ(1U, [cookies count]); | 390 EXPECT_EQ(1U, [cookies count]); |
| 391 EXPECT_TRUE([@"C" isEqualToString:[[cookies lastObject] title]]); | 391 EXPECT_NSEQ(@"C", [[cookies lastObject] title]); |
| 392 EXPECT_TRUE([indexPath isEqual:[treeController selectionIndexPath]]); | 392 EXPECT_NSEQ(indexPath, [treeController selectionIndexPath]); |
| 393 | 393 |
| 394 // Select cookie E. | 394 // Select cookie E. |
| 395 NSUInteger pathE[3] = {1, 0, 0}; | 395 NSUInteger pathE[3] = {1, 0, 0}; |
| 396 indexPath = [NSIndexPath indexPathWithIndexes:pathE length:3]; | 396 indexPath = [NSIndexPath indexPathWithIndexes:pathE length:3]; |
| 397 [treeController setSelectionIndexPath:indexPath]; | 397 [treeController setSelectionIndexPath:indexPath]; |
| 398 | 398 |
| 399 // Perform delete. | 399 // Perform delete. |
| 400 [controller deleteCookie:nil]; | 400 [controller deleteCookie:nil]; |
| 401 | 401 |
| 402 // Make sure that both the domain level node and the Cookies folder node got | 402 // Make sure that both the domain level node and the Cookies folder node got |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 databaseHelper:database_helper_ | 624 databaseHelper:database_helper_ |
| 625 storageHelper:local_storage_helper_ | 625 storageHelper:local_storage_helper_ |
| 626 appcacheHelper:appcache_helper_]); | 626 appcacheHelper:appcache_helper_]); |
| 627 database_helper_->Notify(); | 627 database_helper_->Notify(); |
| 628 | 628 |
| 629 ASSERT_EQ(2U, [[[controller_ cocoaTreeModel] children] count]); | 629 ASSERT_EQ(2U, [[[controller_ cocoaTreeModel] children] count]); |
| 630 | 630 |
| 631 // Root --> gdbhost1. | 631 // Root --> gdbhost1. |
| 632 CocoaCookieTreeNode* node = | 632 CocoaCookieTreeNode* node = |
| 633 [[[controller_ cocoaTreeModel] children] objectAtIndex:0]; | 633 [[[controller_ cocoaTreeModel] children] objectAtIndex:0]; |
| 634 EXPECT_TRUE([@"gdbhost1" isEqualToString:[node title]]); | 634 EXPECT_NSEQ(@"gdbhost1", [node title]); |
| 635 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); | 635 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); |
| 636 EXPECT_EQ(1U, [[node children] count]); | 636 EXPECT_EQ(1U, [[node children] count]); |
| 637 | 637 |
| 638 // host1 --> Web Databases. | 638 // host1 --> Web Databases. |
| 639 node = [[node children] lastObject]; | 639 node = [[node children] lastObject]; |
| 640 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_WEB_DATABASES) | 640 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_WEB_DATABASES), [node title]); |
| 641 isEqualToString:[node title]]); | |
| 642 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); | 641 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); |
| 643 EXPECT_EQ(1U, [[node children] count]); | 642 EXPECT_EQ(1U, [[node children] count]); |
| 644 | 643 |
| 645 // Database Storage --> db1. | 644 // Database Storage --> db1. |
| 646 node = [[node children] lastObject]; | 645 node = [[node children] lastObject]; |
| 647 EXPECT_TRUE([@"db1" isEqualToString:[node title]]); | 646 EXPECT_NSEQ(@"db1", [node title]); |
| 648 EXPECT_EQ(kCocoaCookieDetailsTypeTreeDatabase, [node nodeType]); | 647 EXPECT_EQ(kCocoaCookieDetailsTypeTreeDatabase, [node nodeType]); |
| 649 CocoaCookieDetails* details = [node details]; | 648 CocoaCookieDetails* details = [node details]; |
| 650 EXPECT_TRUE([@"description 1" isEqualToString:[details databaseDescription]]); | 649 EXPECT_NSEQ(@"description 1", [details databaseDescription]); |
| 651 EXPECT_TRUE([details lastModified]); | 650 EXPECT_TRUE([details lastModified]); |
| 652 EXPECT_TRUE([details fileSize]); | 651 EXPECT_TRUE([details fileSize]); |
| 653 | 652 |
| 654 // Root --> gdbhost2. | 653 // Root --> gdbhost2. |
| 655 node = | 654 node = |
| 656 [[[controller_ cocoaTreeModel] children] objectAtIndex:1]; | 655 [[[controller_ cocoaTreeModel] children] objectAtIndex:1]; |
| 657 EXPECT_TRUE([@"gdbhost2" isEqualToString:[node title]]); | 656 EXPECT_NSEQ(@"gdbhost2", [node title]); |
| 658 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); | 657 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); |
| 659 EXPECT_EQ(1U, [[node children] count]); | 658 EXPECT_EQ(1U, [[node children] count]); |
| 660 | 659 |
| 661 // host1 --> Web Databases. | 660 // host1 --> Web Databases. |
| 662 node = [[node children] lastObject]; | 661 node = [[node children] lastObject]; |
| 663 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_WEB_DATABASES) | 662 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_WEB_DATABASES), [node title]); |
| 664 isEqualToString:[node title]]); | |
| 665 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); | 663 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); |
| 666 EXPECT_EQ(1U, [[node children] count]); | 664 EXPECT_EQ(1U, [[node children] count]); |
| 667 | 665 |
| 668 // Database Storage --> db2. | 666 // Database Storage --> db2. |
| 669 node = [[node children] lastObject]; | 667 node = [[node children] lastObject]; |
| 670 EXPECT_TRUE([@"db2" isEqualToString:[node title]]); | 668 EXPECT_NSEQ(@"db2", [node title]); |
| 671 EXPECT_EQ(kCocoaCookieDetailsTypeTreeDatabase, [node nodeType]); | 669 EXPECT_EQ(kCocoaCookieDetailsTypeTreeDatabase, [node nodeType]); |
| 672 details = [node details]; | 670 details = [node details]; |
| 673 EXPECT_TRUE([@"description 2" isEqualToString:[details databaseDescription]]); | 671 EXPECT_NSEQ(@"description 2", [details databaseDescription]); |
| 674 EXPECT_TRUE([details lastModified]); | 672 EXPECT_TRUE([details lastModified]); |
| 675 EXPECT_TRUE([details fileSize]); | 673 EXPECT_TRUE([details fileSize]); |
| 676 } | 674 } |
| 677 | 675 |
| 678 TEST_F(CookiesWindowControllerTest, CreateLocalStorageNodes) { | 676 TEST_F(CookiesWindowControllerTest, CreateLocalStorageNodes) { |
| 679 TestingProfile* profile = browser_helper_.profile(); | 677 TestingProfile* profile = browser_helper_.profile(); |
| 680 net::CookieMonster* cm = profile->GetCookieMonster(); | 678 net::CookieMonster* cm = profile->GetCookieMonster(); |
| 681 cm->SetCookie(GURL("http://google.com"), "A=B"); | 679 cm->SetCookie(GURL("http://google.com"), "A=B"); |
| 682 cm->SetCookie(GURL("http://dev.chromium.org"), "C=D"); | 680 cm->SetCookie(GURL("http://dev.chromium.org"), "C=D"); |
| 683 database_helper_ = new MockBrowsingDataDatabaseHelper(profile); | 681 database_helper_ = new MockBrowsingDataDatabaseHelper(profile); |
| 684 local_storage_helper_ = new MockBrowsingDataLocalStorageHelper(profile); | 682 local_storage_helper_ = new MockBrowsingDataLocalStorageHelper(profile); |
| 685 local_storage_helper_->AddLocalStorageSamples(); | 683 local_storage_helper_->AddLocalStorageSamples(); |
| 686 controller_.reset( | 684 controller_.reset( |
| 687 [[CookiesWindowController alloc] initWithProfile:profile | 685 [[CookiesWindowController alloc] initWithProfile:profile |
| 688 databaseHelper:database_helper_ | 686 databaseHelper:database_helper_ |
| 689 storageHelper:local_storage_helper_ | 687 storageHelper:local_storage_helper_ |
| 690 appcacheHelper:appcache_helper_]); | 688 appcacheHelper:appcache_helper_]); |
| 691 local_storage_helper_->Notify(); | 689 local_storage_helper_->Notify(); |
| 692 | 690 |
| 693 ASSERT_EQ(4U, [[[controller_ cocoaTreeModel] children] count]); | 691 ASSERT_EQ(4U, [[[controller_ cocoaTreeModel] children] count]); |
| 694 | 692 |
| 695 // Root --> host1. | 693 // Root --> host1. |
| 696 CocoaCookieTreeNode* node = | 694 CocoaCookieTreeNode* node = |
| 697 [[[controller_ cocoaTreeModel] children] objectAtIndex:2]; | 695 [[[controller_ cocoaTreeModel] children] objectAtIndex:2]; |
| 698 EXPECT_TRUE([@"host1" isEqualToString:[node title]]); | 696 EXPECT_NSEQ(@"host1", [node title]); |
| 699 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); | 697 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); |
| 700 EXPECT_EQ(1U, [[node children] count]); | 698 EXPECT_EQ(1U, [[node children] count]); |
| 701 | 699 |
| 702 // host1 --> Local Storage. | 700 // host1 --> Local Storage. |
| 703 node = [[node children] lastObject]; | 701 node = [[node children] lastObject]; |
| 704 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_LOCAL_STORAGE) | 702 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_LOCAL_STORAGE), [node title]); |
| 705 isEqualToString:[node title]]); | |
| 706 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); | 703 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); |
| 707 EXPECT_EQ(1U, [[node children] count]); | 704 EXPECT_EQ(1U, [[node children] count]); |
| 708 | 705 |
| 709 // Local Storage --> http://host1:1/. | 706 // Local Storage --> http://host1:1/. |
| 710 node = [[node children] lastObject]; | 707 node = [[node children] lastObject]; |
| 711 EXPECT_TRUE([@"http://host1:1/" isEqualToString:[node title]]); | 708 EXPECT_NSEQ(@"http://host1:1/", [node title]); |
| 712 EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); | 709 EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); |
| 713 EXPECT_TRUE([@"http://host1:1/" isEqualToString:[[node details] domain]]); | 710 EXPECT_NSEQ(@"http://host1:1/", [[node details] domain]); |
| 714 EXPECT_TRUE([[node details] lastModified]); | 711 EXPECT_TRUE([[node details] lastModified]); |
| 715 EXPECT_TRUE([[node details] fileSize]); | 712 EXPECT_TRUE([[node details] fileSize]); |
| 716 | 713 |
| 717 // Root --> host2. | 714 // Root --> host2. |
| 718 node = | 715 node = |
| 719 [[[controller_ cocoaTreeModel] children] objectAtIndex:3]; | 716 [[[controller_ cocoaTreeModel] children] objectAtIndex:3]; |
| 720 EXPECT_TRUE([@"host2" isEqualToString:[node title]]); | 717 EXPECT_NSEQ(@"host2", [node title]); |
| 721 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); | 718 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); |
| 722 EXPECT_EQ(1U, [[node children] count]); | 719 EXPECT_EQ(1U, [[node children] count]); |
| 723 | 720 |
| 724 // host2 --> Local Storage. | 721 // host2 --> Local Storage. |
| 725 node = [[node children] lastObject]; | 722 node = [[node children] lastObject]; |
| 726 EXPECT_TRUE([l10n_util::GetNSString(IDS_COOKIES_LOCAL_STORAGE) | 723 EXPECT_NSEQ(l10n_util::GetNSString(IDS_COOKIES_LOCAL_STORAGE), [node title]); |
| 727 isEqualToString:[node title]]); | |
| 728 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); | 724 EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); |
| 729 EXPECT_EQ(1U, [[node children] count]); | 725 EXPECT_EQ(1U, [[node children] count]); |
| 730 | 726 |
| 731 // Local Storage --> http://host2:2/. | 727 // Local Storage --> http://host2:2/. |
| 732 node = [[node children] lastObject]; | 728 node = [[node children] lastObject]; |
| 733 EXPECT_TRUE([@"http://host2:2/" isEqualToString:[node title]]); | 729 EXPECT_NSEQ(@"http://host2:2/", [node title]); |
| 734 EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); | 730 EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); |
| 735 EXPECT_TRUE([@"http://host2:2/" isEqualToString:[[node details] domain]]); | 731 EXPECT_NSEQ(@"http://host2:2/", [[node details] domain]); |
| 736 EXPECT_TRUE([[node details] lastModified]); | 732 EXPECT_TRUE([[node details] lastModified]); |
| 737 EXPECT_TRUE([[node details] fileSize]); | 733 EXPECT_TRUE([[node details] fileSize]); |
| 738 } | 734 } |
| 739 | 735 |
| 740 } // namespace | 736 } // namespace |
| OLD | NEW |