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/theme_provider.h" | 7 #include "app/theme_provider.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/scoped_nsobject.h" | 9 #include "base/scoped_nsobject.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 } | 1007 } |
1008 } | 1008 } |
1009 | 1009 |
1010 TEST_F(BookmarkBarControllerTest, DropBookmarks) { | 1010 TEST_F(BookmarkBarControllerTest, DropBookmarks) { |
1011 const char* urls[] = { | 1011 const char* urls[] = { |
1012 "http://qwantz.com", | 1012 "http://qwantz.com", |
1013 "http://xkcd.com", | 1013 "http://xkcd.com", |
1014 "javascript:alert('lolwut')", | 1014 "javascript:alert('lolwut')", |
1015 "file://localhost/tmp/local-file.txt" // As if dragged from the desktop. | 1015 "file://localhost/tmp/local-file.txt" // As if dragged from the desktop. |
1016 }; | 1016 }; |
1017 std::wstring titles[] = { | 1017 const char* titles[] = { |
1018 std::wstring(L"Philosophoraptor"), | 1018 "Philosophoraptor", |
1019 std::wstring(L"Can't draw"), | 1019 "Can't draw", |
1020 std::wstring(L"Inspiration"), | 1020 "Inspiration", |
1021 std::wstring(L"Frum stuf") | 1021 "Frum stuf" |
1022 }; | 1022 }; |
1023 EXPECT_EQ(arraysize(urls), arraysize(titles)); | 1023 EXPECT_EQ(arraysize(urls), arraysize(titles)); |
1024 | 1024 |
1025 NSMutableArray* nsurls = [NSMutableArray array]; | 1025 NSMutableArray* nsurls = [NSMutableArray array]; |
1026 NSMutableArray* nstitles = [NSMutableArray array]; | 1026 NSMutableArray* nstitles = [NSMutableArray array]; |
1027 for (size_t i = 0; i < arraysize(urls); ++i) { | 1027 for (size_t i = 0; i < arraysize(urls); ++i) { |
1028 [nsurls addObject:base::SysUTF8ToNSString(urls[i])]; | 1028 [nsurls addObject:base::SysUTF8ToNSString(urls[i])]; |
1029 [nstitles addObject:base::SysWideToNSString(titles[i])]; | 1029 [nstitles addObject:base::SysUTF8ToNSString(titles[i])]; |
1030 } | 1030 } |
1031 | 1031 |
1032 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 1032 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
1033 const BookmarkNode* parent = model->GetBookmarkBarNode(); | 1033 const BookmarkNode* parent = model->GetBookmarkBarNode(); |
1034 [bar_ addURLs:nsurls withTitles:nstitles at:NSZeroPoint]; | 1034 [bar_ addURLs:nsurls withTitles:nstitles at:NSZeroPoint]; |
1035 EXPECT_EQ(4, parent->GetChildCount()); | 1035 EXPECT_EQ(4, parent->GetChildCount()); |
1036 for (int i = 0; i < parent->GetChildCount(); ++i) { | 1036 for (int i = 0; i < parent->GetChildCount(); ++i) { |
1037 GURL gurl = parent->GetChild(i)->GetURL(); | 1037 GURL gurl = parent->GetChild(i)->GetURL(); |
1038 if (gurl.scheme() == "http" || | 1038 if (gurl.scheme() == "http" || |
1039 gurl.scheme() == "javascript") { | 1039 gurl.scheme() == "javascript") { |
1040 EXPECT_EQ(parent->GetChild(i)->GetURL(), GURL(urls[i])); | 1040 EXPECT_EQ(parent->GetChild(i)->GetURL(), GURL(urls[i])); |
1041 } else { | 1041 } else { |
1042 // Be flexible if the scheme needed to be added. | 1042 // Be flexible if the scheme needed to be added. |
1043 std::string gurl_string = gurl.spec(); | 1043 std::string gurl_string = gurl.spec(); |
1044 std::string my_string = parent->GetChild(i)->GetURL().spec(); | 1044 std::string my_string = parent->GetChild(i)->GetURL().spec(); |
1045 EXPECT_NE(gurl_string.find(my_string), std::string::npos); | 1045 EXPECT_NE(gurl_string.find(my_string), std::string::npos); |
1046 } | 1046 } |
1047 EXPECT_EQ(parent->GetChild(i)->GetTitle(), titles[i]); | 1047 EXPECT_EQ(parent->GetChild(i)->GetTitleAsString16(), |
| 1048 ASCIIToUTF16(titles[i])); |
1048 } | 1049 } |
1049 } | 1050 } |
1050 | 1051 |
1051 TEST_F(BookmarkBarControllerTest, TestButtonOrBar) { | 1052 TEST_F(BookmarkBarControllerTest, TestButtonOrBar) { |
1052 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 1053 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
1053 GURL gurl1("http://www.google.com"); | 1054 GURL gurl1("http://www.google.com"); |
1054 string16 title1(ASCIIToUTF16("x")); | 1055 string16 title1(ASCIIToUTF16("x")); |
1055 model->SetURLStarred(gurl1, title1, true); | 1056 model->SetURLStarred(gurl1, title1, true); |
1056 | 1057 |
1057 GURL gurl2("http://www.google.com/gurl_power"); | 1058 GURL gurl2("http://www.google.com/gurl_power"); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 const BookmarkNode* folder = model->AddGroup(model->GetBookmarkBarNode(), | 1160 const BookmarkNode* folder = model->AddGroup(model->GetBookmarkBarNode(), |
1160 0, | 1161 0, |
1161 ASCIIToUTF16("awesome group")); | 1162 ASCIIToUTF16("awesome group")); |
1162 DCHECK(folder); | 1163 DCHECK(folder); |
1163 model->AddURL(folder, 0, ASCIIToUTF16("already"), | 1164 model->AddURL(folder, 0, ASCIIToUTF16("already"), |
1164 GURL("http://www.google.com")); | 1165 GURL("http://www.google.com")); |
1165 EXPECT_EQ(arraysize(titles) + 1, [[bar_ buttons] count]); | 1166 EXPECT_EQ(arraysize(titles) + 1, [[bar_ buttons] count]); |
1166 EXPECT_EQ(1, folder->GetChildCount()); | 1167 EXPECT_EQ(1, folder->GetChildCount()); |
1167 x = NSMidX([[[bar_ buttons] objectAtIndex:0] frame]); | 1168 x = NSMidX([[[bar_ buttons] objectAtIndex:0] frame]); |
1168 x += [[bar_ view] frame].origin.x; | 1169 x += [[bar_ view] frame].origin.x; |
1169 std::wstring title = [[[bar_ buttons] objectAtIndex:2] | 1170 string16 title = |
1170 bookmarkNode]->GetTitle(); | 1171 [[[bar_ buttons] objectAtIndex:2] bookmarkNode]->GetTitleAsString16(); |
1171 [bar_ dragButton:[[bar_ buttons] objectAtIndex:2] | 1172 [bar_ dragButton:[[bar_ buttons] objectAtIndex:2] |
1172 to:NSMakePoint(x, 0) | 1173 to:NSMakePoint(x, 0) |
1173 copy:NO]; | 1174 copy:NO]; |
1174 // Gone from the bar | 1175 // Gone from the bar |
1175 EXPECT_EQ(arraysize(titles), [[bar_ buttons] count]); | 1176 EXPECT_EQ(arraysize(titles), [[bar_ buttons] count]); |
1176 // In the folder | 1177 // In the folder |
1177 EXPECT_EQ(2, folder->GetChildCount()); | 1178 EXPECT_EQ(2, folder->GetChildCount()); |
1178 // At the end | 1179 // At the end |
1179 EXPECT_EQ(title, folder->GetChild(1)->GetTitle()); | 1180 EXPECT_EQ(title, folder->GetChild(1)->GetTitleAsString16()); |
1180 } | 1181 } |
1181 | 1182 |
1182 TEST_F(BookmarkBarControllerTest, TestCopyButton) { | 1183 TEST_F(BookmarkBarControllerTest, TestCopyButton) { |
1183 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 1184 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
1184 | 1185 |
1185 GURL gurls[] = { GURL("http://www.google.com/a"), | 1186 GURL gurls[] = { GURL("http://www.google.com/a"), |
1186 GURL("http://www.google.com/b"), | 1187 GURL("http://www.google.com/b"), |
1187 GURL("http://www.google.com/c") }; | 1188 GURL("http://www.google.com/c") }; |
1188 string16 titles[] = { ASCIIToUTF16("a"), | 1189 string16 titles[] = { ASCIIToUTF16("a"), |
1189 ASCIIToUTF16("b"), | 1190 ASCIIToUTF16("b"), |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 "2f3b ] O3f:[ O3f1b O3f2f ] 3b 4b "); | 1941 "2f3b ] O3f:[ O3f1b O3f2f ] 3b 4b "); |
1941 actual = model_test_utils::ModelStringFromNode(root); | 1942 actual = model_test_utils::ModelStringFromNode(root); |
1942 EXPECT_EQ(expected, actual); | 1943 EXPECT_EQ(expected, actual); |
1943 oldChildCount = newChildCount; | 1944 oldChildCount = newChildCount; |
1944 | 1945 |
1945 // Now do it over a folder button. | 1946 // Now do it over a folder button. |
1946 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; | 1947 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; |
1947 ASSERT_TRUE(targetButton); | 1948 ASSERT_TRUE(targetButton); |
1948 NSPoint targetPoint = [targetButton center]; | 1949 NSPoint targetPoint = [targetButton center]; |
1949 newNode = other->GetChild(2); // Should be O4f. | 1950 newNode = other->GetChild(2); // Should be O4f. |
1950 EXPECT_EQ(newNode->GetTitle(), L"O4f"); | 1951 EXPECT_EQ(newNode->GetTitleAsString16(), ASCIIToUTF16("O4f")); |
1951 [bar_ setDragDataNode:newNode]; | 1952 [bar_ setDragDataNode:newNode]; |
1952 [dragInfo setDropLocation:targetPoint]; | 1953 [dragInfo setDropLocation:targetPoint]; |
1953 [bar_ dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; | 1954 [bar_ dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; |
1954 | 1955 |
1955 newChildCount = root->GetChildCount(); | 1956 newChildCount = root->GetChildCount(); |
1956 EXPECT_EQ(oldChildCount, newChildCount); | 1957 EXPECT_EQ(oldChildCount, newChildCount); |
1957 // Verify the model. | 1958 // Verify the model. |
1958 const std::wstring expected1(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 1959 const std::wstring expected1(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
1959 "2f3b O4f:[ O4f1b O4f2f ] ] O3f:[ O3f1b O3f2f ] " | 1960 "2f3b O4f:[ O4f1b O4f2f ] ] O3f:[ O3f1b O3f2f ] " |
1960 "3b 4b "); | 1961 "3b 4b "); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 bookmark_button::kBookmarkPulseFlagKey, | 2072 bookmark_button::kBookmarkPulseFlagKey, |
2072 nil]; | 2073 nil]; |
2073 [[NSNotificationCenter defaultCenter] | 2074 [[NSNotificationCenter defaultCenter] |
2074 postNotificationName:bookmark_button::kPulseBookmarkButtonNotification | 2075 postNotificationName:bookmark_button::kPulseBookmarkButtonNotification |
2075 object:nil | 2076 object:nil |
2076 userInfo:dict]; | 2077 userInfo:dict]; |
2077 EXPECT_FALSE([button isContinuousPulsing]); | 2078 EXPECT_FALSE([button isContinuousPulsing]); |
2078 } | 2079 } |
2079 | 2080 |
2080 } // namespace | 2081 } // namespace |
OLD | NEW |