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 10 matching lines...) Expand all Loading... | |
35 uint32_t* src_data = bmp->getAddr32(0, 0); | 36 uint32_t* src_data = bmp->getAddr32(0, 0); |
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() { |
Paweł Hajdan Jr.
2011/04/08 15:58:17
Oh, could you also make it call the parent's SetUp
Mike West
2011/04/11 14:47:04
Done.
| |
46 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_)); | 47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
47 path_ = path_.AppendASCII("bookmarks.html"); | 48 path_ = temp_dir_.path().AppendASCII("bookmarks.html"); |
48 file_util::Delete(path_, true); | 49 file_util::Delete(path_, true); |
Paweł Hajdan Jr.
2011/04/08 15:58:17
Shouldn't be needed.
Mike West
2011/04/11 14:47:04
Done.
| |
49 } | 50 } |
50 | 51 |
51 virtual void TearDown() { | 52 virtual void TearDown() { |
Paweł Hajdan Jr.
2011/04/08 15:58:17
Can you remove it entirely then?
Mike West
2011/04/11 14:47:04
Done.
| |
52 if (!path_.empty()) | |
53 file_util::Delete(path_, true); | |
54 } | 53 } |
55 | 54 |
56 // Converts a BookmarkEntry to a string suitable for assertion testing. | 55 // Converts a BookmarkEntry to a string suitable for assertion testing. |
57 string16 BookmarkEntryToString( | 56 string16 BookmarkEntryToString( |
58 const ProfileWriter::BookmarkEntry& entry) { | 57 const ProfileWriter::BookmarkEntry& entry) { |
59 string16 result; | 58 string16 result; |
60 result.append(ASCIIToUTF16("on_toolbar=")); | 59 result.append(ASCIIToUTF16("on_toolbar=")); |
61 if (entry.in_toolbar) | 60 if (entry.in_toolbar) |
62 result.append(ASCIIToUTF16("false")); | 61 result.append(ASCIIToUTF16("false")); |
63 else | 62 else |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 const string16& title, | 112 const string16& title, |
114 base::Time creation_time, | 113 base::Time creation_time, |
115 const string16& f1, | 114 const string16& f1, |
116 const string16& f2, | 115 const string16& f2, |
117 const string16& f3) { | 116 const string16& f3) { |
118 EXPECT_EQ(BookmarkValuesToString(on_toolbar, url, title, creation_time, | 117 EXPECT_EQ(BookmarkValuesToString(on_toolbar, url, title, creation_time, |
119 f1, f2, f3), | 118 f1, f2, f3), |
120 BookmarkEntryToString(entry)); | 119 BookmarkEntryToString(entry)); |
121 } | 120 } |
122 | 121 |
122 ScopedTempDir temp_dir_; | |
123 FilePath path_; | 123 FilePath path_; |
124 }; | 124 }; |
125 | 125 |
126 // Class that will notify message loop when file is written. | 126 // Class that will notify message loop when file is written. |
127 class BookmarksObserver : public BookmarksExportObserver { | 127 class BookmarksObserver : public BookmarksExportObserver { |
128 public: | 128 public: |
129 explicit BookmarksObserver(MessageLoop* loop) : loop_(loop) { | 129 explicit BookmarksObserver(MessageLoop* loop) : loop_(loop) { |
130 DCHECK(loop); | 130 DCHECK(loop); |
131 } | 131 } |
132 | 132 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 bookmark_folder_name, string16(), string16()); | 260 bookmark_folder_name, string16(), string16()); |
261 AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url4, url4_title, t4, | 261 AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url4, url4_title, t4, |
262 bookmark_folder_name, string16(), string16()); | 262 bookmark_folder_name, string16(), string16()); |
263 AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url1, url1_title, t1, | 263 AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url1, url1_title, t1, |
264 string16(), string16(), string16()); | 264 string16(), string16(), string16()); |
265 AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2, | 265 AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2, |
266 string16(), string16(), string16()); | 266 string16(), string16(), string16()); |
267 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, | 267 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, |
268 f3_title, f4_title, string16()); | 268 f3_title, f4_title, string16()); |
269 } | 269 } |
OLD | NEW |