OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/bookmarks/bookmark_html_writer.h" | 10 #include "chrome/browser/bookmarks/bookmark_html_writer.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // Tests bookmark_html_writer by populating a BookmarkModel, writing it out by | 58 // Tests bookmark_html_writer by populating a BookmarkModel, writing it out by |
59 // way of bookmark_html_writer, then using the importer to read it back in. | 59 // way of bookmark_html_writer, then using the importer to read it back in. |
60 TEST_F(BookmarkHTMLWriterTest, Test) { | 60 TEST_F(BookmarkHTMLWriterTest, Test) { |
61 // Populate the BookmarkModel. This creates the following bookmark structure: | 61 // Populate the BookmarkModel. This creates the following bookmark structure: |
62 // Bookmarks bar | 62 // Bookmarks bar |
63 // F1 | 63 // F1 |
64 // url1 | 64 // url1 |
65 // F2 | 65 // F2 |
66 // url2 | 66 // url2 |
67 // url3 | 67 // url3 |
| 68 // url4 |
68 // Other | 69 // Other |
69 // url1 | 70 // url1 |
70 // url2 | 71 // url2 |
71 // F3 | 72 // F3 |
72 // F4 | 73 // F4 |
73 // url1 | 74 // url1 |
74 std::wstring f1_title = L"F\"&;<1\""; | 75 std::wstring f1_title = L"F\"&;<1\""; |
75 std::wstring f2_title = L"F2"; | 76 std::wstring f2_title = L"F2"; |
76 std::wstring f3_title = L"F 3"; | 77 std::wstring f3_title = L"F 3"; |
77 std::wstring f4_title = L"F4"; | 78 std::wstring f4_title = L"F4"; |
78 std::wstring url1_title = L"url 1"; | 79 std::wstring url1_title = L"url 1"; |
79 std::wstring url2_title = L"url&2"; | 80 std::wstring url2_title = L"url&2"; |
80 std::wstring url3_title = L"url\"3"; | 81 std::wstring url3_title = L"url\"3"; |
| 82 std::wstring url4_title = L"url\"&;"; |
81 GURL url1("http://url1"); | 83 GURL url1("http://url1"); |
82 GURL url2("http://url2"); | 84 GURL url2("http://url2"); |
83 GURL url3("http://url3"); | 85 GURL url3("http://url3"); |
| 86 GURL url4("http://\"&;\""); |
84 BookmarkModel model(NULL); | 87 BookmarkModel model(NULL); |
85 base::Time t1(base::Time::Now()); | 88 base::Time t1(base::Time::Now()); |
86 base::Time t2(t1 + base::TimeDelta::FromHours(1)); | 89 base::Time t2(t1 + base::TimeDelta::FromHours(1)); |
87 base::Time t3(t1 + base::TimeDelta::FromHours(1)); | 90 base::Time t3(t1 + base::TimeDelta::FromHours(1)); |
| 91 base::Time t4(t1 + base::TimeDelta::FromHours(1)); |
88 const BookmarkNode* f1 = model.AddGroup( | 92 const BookmarkNode* f1 = model.AddGroup( |
89 model.GetBookmarkBarNode(), 0, f1_title); | 93 model.GetBookmarkBarNode(), 0, f1_title); |
90 model.AddURLWithCreationTime(f1, 0, url1_title, url1, t1); | 94 model.AddURLWithCreationTime(f1, 0, url1_title, url1, t1); |
91 const BookmarkNode* f2 = model.AddGroup(f1, 1, f2_title); | 95 const BookmarkNode* f2 = model.AddGroup(f1, 1, f2_title); |
92 model.AddURLWithCreationTime(f2, 0, url2_title, url2, t2); | 96 model.AddURLWithCreationTime(f2, 0, url2_title, url2, t2); |
93 model.AddURLWithCreationTime(model.GetBookmarkBarNode(), 1, url3_title, url3, | 97 model.AddURLWithCreationTime(model.GetBookmarkBarNode(), 1, url3_title, url3, |
94 t3); | 98 t3); |
95 | 99 |
96 model.AddURLWithCreationTime(model.other_node(), 0, url1_title, url1, t1); | 100 model.AddURLWithCreationTime(model.other_node(), 0, url1_title, url1, t1); |
97 model.AddURLWithCreationTime(model.other_node(), 1, url2_title, url2, t2); | 101 model.AddURLWithCreationTime(model.other_node(), 1, url2_title, url2, t2); |
98 const BookmarkNode* f3 = model.AddGroup(model.other_node(), 2, f3_title); | 102 const BookmarkNode* f3 = model.AddGroup(model.other_node(), 2, f3_title); |
99 const BookmarkNode* f4 = model.AddGroup(f3, 0, f4_title); | 103 const BookmarkNode* f4 = model.AddGroup(f3, 0, f4_title); |
100 model.AddURLWithCreationTime(f4, 0, url1_title, url1, t1); | 104 model.AddURLWithCreationTime(f4, 0, url1_title, url1, t1); |
| 105 model.AddURLWithCreationTime(model.GetBookmarkBarNode(), 2, url4_title, |
| 106 url4, t4); |
101 | 107 |
102 // Write to a temp file. | 108 // Write to a temp file. |
103 bookmark_html_writer::WriteBookmarks(NULL, &model, path_.ToWStringHack()); | 109 bookmark_html_writer::WriteBookmarks(NULL, &model, path_.ToWStringHack()); |
104 | 110 |
105 // Read the bookmarks back in. | 111 // Read the bookmarks back in. |
106 std::vector<ProfileWriter::BookmarkEntry> parsed_bookmarks; | 112 std::vector<ProfileWriter::BookmarkEntry> parsed_bookmarks; |
107 Firefox2Importer::ImportBookmarksFile(path_.ToWStringHack(), std::set<GURL>(), | 113 Firefox2Importer::ImportBookmarksFile(path_.ToWStringHack(), std::set<GURL>(), |
108 false, L"x", NULL, &parsed_bookmarks, | 114 false, L"x", NULL, &parsed_bookmarks, |
109 NULL, NULL); | 115 NULL, NULL); |
110 | 116 |
111 // Verify we got back what we wrote. | 117 // Verify we got back what we wrote. |
112 ASSERT_EQ(6U, parsed_bookmarks.size()); | 118 ASSERT_EQ(7U, parsed_bookmarks.size()); |
113 // Hardcode the value of IDS_BOOKMARK_BAR_FOLDER_NAME in en-US locale | 119 // Hardcode the value of IDS_BOOKMARK_BAR_FOLDER_NAME in en-US locale |
114 // because all the unit tests are run in en-US locale. | 120 // because all the unit tests are run in en-US locale. |
115 const wchar_t* kBookmarkBarFolderName = L"Bookmarks bar"; | 121 const wchar_t* kBookmarkBarFolderName = L"Bookmarks bar"; |
116 AssertBookmarkEntryEquals(parsed_bookmarks[0], false, url1, url1_title, t1, | 122 AssertBookmarkEntryEquals(parsed_bookmarks[0], false, url1, url1_title, t1, |
117 kBookmarkBarFolderName, f1_title, std::wstring()); | 123 kBookmarkBarFolderName, f1_title, std::wstring()); |
118 AssertBookmarkEntryEquals(parsed_bookmarks[1], false, url2, url2_title, t2, | 124 AssertBookmarkEntryEquals(parsed_bookmarks[1], false, url2, url2_title, t2, |
119 kBookmarkBarFolderName, f1_title, f2_title); | 125 kBookmarkBarFolderName, f1_title, f2_title); |
120 AssertBookmarkEntryEquals(parsed_bookmarks[2], false, url3, url3_title, t3, | 126 AssertBookmarkEntryEquals(parsed_bookmarks[2], false, url3, url3_title, t3, |
121 kBookmarkBarFolderName, std::wstring(), | 127 kBookmarkBarFolderName, std::wstring(), |
122 std::wstring()); | 128 std::wstring()); |
123 AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url1, url1_title, t1, | 129 AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url4, url4_title, t4, |
| 130 kBookmarkBarFolderName, std::wstring(), |
| 131 std::wstring()); |
| 132 AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url1, url1_title, t1, |
124 std::wstring(), std::wstring(), std::wstring()); | 133 std::wstring(), std::wstring(), std::wstring()); |
125 AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url2, url2_title, t2, | 134 AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2, |
126 std::wstring(), std::wstring(), std::wstring()); | 135 std::wstring(), std::wstring(), std::wstring()); |
127 AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url1, url1_title, t1, | 136 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, |
128 f3_title, f4_title, std::wstring()); | 137 f3_title, f4_title, std::wstring()); |
129 } | 138 } |
OLD | NEW |