OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/sys_string_conversions.h" | |
6 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
7 #include "chrome/browser/ui/cocoa/cookie_details.h" | |
8 #include "chrome/browser/ui/cocoa/cookie_details_view_controller.h" | |
9 | |
10 namespace { | |
11 | |
12 class CookieDetailsViewControllerTest : public CocoaTest { | |
13 }; | |
14 | |
15 static CocoaCookieDetails* CreateTestCookieDetails(BOOL canEditExpiration) { | |
16 GURL url("http://chromium.org"); | |
17 std::string cookieLine( | |
18 "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); | |
19 net::CookieMonster::ParsedCookie pc(cookieLine); | |
20 net::CookieMonster::CanonicalCookie cookie(url, pc); | |
21 NSString* origin = base::SysUTF8ToNSString("http://chromium.org"); | |
22 CocoaCookieDetails* details = [CocoaCookieDetails alloc]; | |
23 [details initWithCookie:&cookie | |
24 origin:origin | |
25 canEditExpiration:canEditExpiration]; | |
26 return [details autorelease]; | |
27 } | |
28 | |
29 static CookiePromptContentDetailsAdapter* CreateCookieTestContent( | |
30 BOOL canEditExpiration) { | |
31 CocoaCookieDetails* details = CreateTestCookieDetails(canEditExpiration); | |
32 return [[[CookiePromptContentDetailsAdapter alloc] initWithDetails:details] | |
33 autorelease]; | |
34 } | |
35 | |
36 static CocoaCookieDetails* CreateTestDatabaseDetails() { | |
37 std::string domain("chromium.org"); | |
38 string16 name(base::SysNSStringToUTF16(@"wicked_name")); | |
39 string16 desc(base::SysNSStringToUTF16(@"wicked_desc")); | |
40 CocoaCookieDetails* details = [CocoaCookieDetails alloc]; | |
41 [details initWithDatabase:domain | |
42 databaseName:name | |
43 databaseDescription:desc | |
44 fileSize:2222]; | |
45 return [details autorelease]; | |
46 } | |
47 | |
48 static CookiePromptContentDetailsAdapter* CreateDatabaseTestContent() { | |
49 CocoaCookieDetails* details = CreateTestDatabaseDetails(); | |
50 return [[[CookiePromptContentDetailsAdapter alloc] initWithDetails:details] | |
51 autorelease]; | |
52 } | |
53 | |
54 TEST_F(CookieDetailsViewControllerTest, Create) { | |
55 scoped_nsobject<CookieDetailsViewController> detailsViewController( | |
56 [[CookieDetailsViewController alloc] init]); | |
57 } | |
58 | |
59 TEST_F(CookieDetailsViewControllerTest, ShrinkToFit) { | |
60 scoped_nsobject<CookieDetailsViewController> detailsViewController( | |
61 [[CookieDetailsViewController alloc] init]); | |
62 scoped_nsobject<CookiePromptContentDetailsAdapter> adapter( | |
63 [CreateDatabaseTestContent() retain]); | |
64 [detailsViewController.get() setContentObject:adapter.get()]; | |
65 NSRect beforeFrame = [[detailsViewController.get() view] frame]; | |
66 [detailsViewController.get() shrinkViewToFit]; | |
67 NSRect afterFrame = [[detailsViewController.get() view] frame]; | |
68 | |
69 EXPECT_TRUE(afterFrame.size.height < beforeFrame.size.width); | |
70 } | |
71 | |
72 TEST_F(CookieDetailsViewControllerTest, ExpirationEditability) { | |
73 scoped_nsobject<CookieDetailsViewController> detailsViewController( | |
74 [[CookieDetailsViewController alloc] init]); | |
75 [detailsViewController view]; | |
76 scoped_nsobject<CookiePromptContentDetailsAdapter> adapter( | |
77 [CreateCookieTestContent(YES) retain]); | |
78 [detailsViewController.get() setContentObject:adapter.get()]; | |
79 | |
80 EXPECT_FALSE([detailsViewController.get() hasExpiration]); | |
81 [detailsViewController.get() setCookieHasExplicitExpiration:adapter.get()]; | |
82 EXPECT_TRUE([detailsViewController.get() hasExpiration]); | |
83 [detailsViewController.get() | |
84 setCookieDoesntHaveExplicitExpiration:adapter.get()]; | |
85 EXPECT_FALSE([detailsViewController.get() hasExpiration]); | |
86 } | |
87 | |
88 } // namespace | |
OLD | NEW |