OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
| 15 #include "base/memory/scoped_temp_dir.h" |
15 #include "chrome/browser/bookmarks/bookmark_html_writer.h" | 16 #include "chrome/browser/bookmarks/bookmark_html_writer.h" |
16 #include "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
17 #include "chrome/browser/importer/firefox2_importer.h" | 18 #include "chrome/browser/importer/firefox2_importer.h" |
18 #include "chrome/test/testing_browser_process_test.h" | 19 #include "chrome/test/testing_browser_process_test.h" |
19 #include "chrome/test/testing_profile.h" | 20 #include "chrome/test/testing_profile.h" |
20 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
22 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/gfx/codec/png_codec.h" | 25 #include "ui/gfx/codec/png_codec.h" |
(...skipping 11 matching lines...) Expand all Loading... |
36 for (int i = 0; i < w * h; i++) { | 37 for (int i = 0; i < w * h; i++) { |
37 src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240); | 38 src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240); |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 class BookmarkHTMLWriterTest : public TestingBrowserProcessTest { | 44 class BookmarkHTMLWriterTest : public TestingBrowserProcessTest { |
44 protected: | 45 protected: |
45 virtual void SetUp() { | 46 virtual void SetUp() { |
46 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_)); | 47 TestingBrowserProcessTest::SetUp(); |
47 path_ = path_.AppendASCII("bookmarks.html"); | 48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
48 file_util::Delete(path_, true); | 49 path_ = temp_dir_.path().AppendASCII("bookmarks.html"); |
49 } | |
50 | |
51 virtual void TearDown() { | |
52 if (!path_.empty()) | |
53 file_util::Delete(path_, true); | |
54 } | 50 } |
55 | 51 |
56 // Converts a BookmarkEntry to a string suitable for assertion testing. | 52 // Converts a BookmarkEntry to a string suitable for assertion testing. |
57 string16 BookmarkEntryToString( | 53 string16 BookmarkEntryToString( |
58 const ProfileWriter::BookmarkEntry& entry) { | 54 const ProfileWriter::BookmarkEntry& entry) { |
59 string16 result; | 55 string16 result; |
60 result.append(ASCIIToUTF16("on_toolbar=")); | 56 result.append(ASCIIToUTF16("on_toolbar=")); |
61 if (entry.in_toolbar) | 57 if (entry.in_toolbar) |
62 result.append(ASCIIToUTF16("false")); | 58 result.append(ASCIIToUTF16("false")); |
63 else | 59 else |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 const string16& title, | 109 const string16& title, |
114 base::Time creation_time, | 110 base::Time creation_time, |
115 const string16& f1, | 111 const string16& f1, |
116 const string16& f2, | 112 const string16& f2, |
117 const string16& f3) { | 113 const string16& f3) { |
118 EXPECT_EQ(BookmarkValuesToString(on_toolbar, url, title, creation_time, | 114 EXPECT_EQ(BookmarkValuesToString(on_toolbar, url, title, creation_time, |
119 f1, f2, f3), | 115 f1, f2, f3), |
120 BookmarkEntryToString(entry)); | 116 BookmarkEntryToString(entry)); |
121 } | 117 } |
122 | 118 |
| 119 ScopedTempDir temp_dir_; |
123 FilePath path_; | 120 FilePath path_; |
124 }; | 121 }; |
125 | 122 |
126 // Class that will notify message loop when file is written. | 123 // Class that will notify message loop when file is written. |
127 class BookmarksObserver : public BookmarksExportObserver { | 124 class BookmarksObserver : public BookmarksExportObserver { |
128 public: | 125 public: |
129 explicit BookmarksObserver(MessageLoop* loop) : loop_(loop) { | 126 explicit BookmarksObserver(MessageLoop* loop) : loop_(loop) { |
130 DCHECK(loop); | 127 DCHECK(loop); |
131 } | 128 } |
132 | 129 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 bookmark_folder_name, string16(), string16()); | 257 bookmark_folder_name, string16(), string16()); |
261 AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url4, url4_title, t4, | 258 AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url4, url4_title, t4, |
262 bookmark_folder_name, string16(), string16()); | 259 bookmark_folder_name, string16(), string16()); |
263 AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url1, url1_title, t1, | 260 AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url1, url1_title, t1, |
264 string16(), string16(), string16()); | 261 string16(), string16(), string16()); |
265 AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2, | 262 AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2, |
266 string16(), string16(), string16()); | 263 string16(), string16(), string16()); |
267 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, | 264 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, |
268 f3_title, f4_title, string16()); | 265 f3_title, f4_title, string16()); |
269 } | 266 } |
OLD | NEW |