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/tree_model.h" | 7 #include "app/tree_model.h" |
8 #import "base/scoped_nsobject.h" | 8 #import "base/scoped_nsobject.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "chrome/browser/cocoa/browser_test_helper.h" | 10 #include "chrome/browser/cocoa/browser_test_helper.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 EXPECT_TRUE([@"Silly Change" isEqualToString:[cocoa_node title]]); | 355 EXPECT_TRUE([@"Silly Change" isEqualToString:[cocoa_node title]]); |
356 } | 356 } |
357 | 357 |
358 TEST_F(CookiesWindowControllerTest, DeleteCookie) { | 358 TEST_F(CookiesWindowControllerTest, DeleteCookie) { |
359 const GURL url = GURL("http://foo.com"); | 359 const GURL url = GURL("http://foo.com"); |
360 TestingProfile* profile = browser_helper_.profile(); | 360 TestingProfile* profile = browser_helper_.profile(); |
361 net::CookieMonster* cm = profile->GetCookieMonster(); | 361 net::CookieMonster* cm = profile->GetCookieMonster(); |
362 cm->SetCookie(url, "A=B"); | 362 cm->SetCookie(url, "A=B"); |
363 cm->SetCookie(url, "C=D"); | 363 cm->SetCookie(url, "C=D"); |
| 364 cm->SetCookie(GURL("http://google.com"), "E=F"); |
364 | 365 |
365 // This will clean itself up when we call |-closeSheet:|. If we reset the | 366 // This will clean itself up when we call |-closeSheet:|. If we reset the |
366 // scoper, we'd get a double-free. | 367 // scoper, we'd get a double-free. |
367 CookiesWindowController* controller = | 368 CookiesWindowController* controller = |
368 [[CookiesWindowController alloc] initWithProfile:profile | 369 [[CookiesWindowController alloc] initWithProfile:profile |
369 databaseHelper:database_helper_ | 370 databaseHelper:database_helper_ |
370 storageHelper:local_storage_helper_ | 371 storageHelper:local_storage_helper_ |
371 appcacheHelper:appcache_helper_]; | 372 appcacheHelper:appcache_helper_]; |
372 [controller attachSheetTo:test_window()]; | 373 [controller attachSheetTo:test_window()]; |
373 NSTreeController* treeController = [controller treeController]; | 374 NSTreeController* treeController = [controller treeController]; |
374 | 375 |
375 // Pretend to select cookie A. | 376 // Select cookie A. |
376 NSUInteger path[3] = {0, 0, 0}; | 377 NSUInteger pathA[3] = {0, 0, 0}; |
377 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; | 378 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:pathA length:3]; |
378 [treeController setSelectionIndexPath:indexPath]; | 379 [treeController setSelectionIndexPath:indexPath]; |
379 | 380 |
380 // Press the "Delete" button. | 381 // Press the "Delete" button. |
381 [controller deleteCookie:nil]; | 382 [controller deleteCookie:nil]; |
382 | 383 |
383 // Root --> foo.com --> Cookies. | 384 // Root --> foo.com --> Cookies. |
384 NSArray* cookies = [[[[[[controller cocoaTreeModel] children] | 385 NSArray* cookies = [[[[[[controller cocoaTreeModel] children] |
385 objectAtIndex:0] children] objectAtIndex:0] children]; | 386 objectAtIndex:0] children] objectAtIndex:0] children]; |
386 EXPECT_EQ(1U, [cookies count]); | 387 EXPECT_EQ(1U, [cookies count]); |
387 EXPECT_TRUE([@"C" isEqualToString:[[cookies lastObject] title]]); | 388 EXPECT_TRUE([@"C" isEqualToString:[[cookies lastObject] title]]); |
388 EXPECT_TRUE([indexPath isEqual:[treeController selectionIndexPath]]); | 389 EXPECT_TRUE([indexPath isEqual:[treeController selectionIndexPath]]); |
389 | 390 |
| 391 // Select cookie E. |
| 392 NSUInteger pathE[3] = {1, 0, 0}; |
| 393 indexPath = [NSIndexPath indexPathWithIndexes:pathE length:3]; |
| 394 [treeController setSelectionIndexPath:indexPath]; |
| 395 |
| 396 // Perform delete. |
| 397 [controller deleteCookie:nil]; |
| 398 |
| 399 // Make sure that both the domain level node and the Cookies folder node got |
| 400 // deleted because there was only one leaf node. |
| 401 EXPECT_EQ(1U, [[[controller cocoaTreeModel] children] count]); |
| 402 |
| 403 // Select cookie C. |
| 404 NSUInteger pathC[3] = {0, 0, 0}; |
| 405 indexPath = [NSIndexPath indexPathWithIndexes:pathC length:3]; |
| 406 [treeController setSelectionIndexPath:indexPath]; |
| 407 |
| 408 // Perform delete. |
| 409 [controller deleteCookie:nil]; |
| 410 |
| 411 // Make sure the world didn't explode and that there's nothing in the tree. |
| 412 EXPECT_EQ(0U, [[[controller cocoaTreeModel] children] count]); |
| 413 |
390 [controller closeSheet:nil]; | 414 [controller closeSheet:nil]; |
391 } | 415 } |
392 | 416 |
393 TEST_F(CookiesWindowControllerTest, DidExpandItem) { | 417 TEST_F(CookiesWindowControllerTest, DidExpandItem) { |
394 const GURL url = GURL("http://foo.com"); | 418 const GURL url = GURL("http://foo.com"); |
395 TestingProfile* profile = browser_helper_.profile(); | 419 TestingProfile* profile = browser_helper_.profile(); |
396 net::CookieMonster* cm = profile->GetCookieMonster(); | 420 net::CookieMonster* cm = profile->GetCookieMonster(); |
397 cm->SetCookie(url, "A=B"); | 421 cm->SetCookie(url, "A=B"); |
398 cm->SetCookie(url, "C=D"); | 422 cm->SetCookie(url, "C=D"); |
399 | 423 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 // Local Storage --> origin2. | 724 // Local Storage --> origin2. |
701 node = [[node children] lastObject]; | 725 node = [[node children] lastObject]; |
702 EXPECT_TRUE([@"origin2" isEqualToString:[node title]]); | 726 EXPECT_TRUE([@"origin2" isEqualToString:[node title]]); |
703 EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); | 727 EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); |
704 EXPECT_TRUE([@"origin2" isEqualToString:[[node details] domain]]); | 728 EXPECT_TRUE([@"origin2" isEqualToString:[[node details] domain]]); |
705 EXPECT_TRUE([[node details] lastModified]); | 729 EXPECT_TRUE([[node details] lastModified]); |
706 EXPECT_TRUE([[node details] fileSize]); | 730 EXPECT_TRUE([[node details] fileSize]); |
707 } | 731 } |
708 | 732 |
709 } // namespace | 733 } // namespace |
OLD | NEW |