Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Side by Side Diff: chrome/browser/history/android/android_provider_backend_unittest.cc

Issue 531493002: Move encoding SkBitmaps to PNG out of FaviconService::SetFavicons() and onto the history thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/favicon/favicon_service.cc ('k') | chrome/browser/history/history_backend.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/history/android/android_provider_backend.h" 5 #include "chrome/browser/history/android/android_provider_backend.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/testing_profile_manager.h" 26 #include "chrome/test/base/testing_profile_manager.h"
27 #include "components/bookmarks/browser/bookmark_model.h" 27 #include "components/bookmarks/browser/bookmark_model.h"
28 #include "components/bookmarks/test/bookmark_test_helpers.h" 28 #include "components/bookmarks/test/bookmark_test_helpers.h"
29 #include "components/history/core/browser/keyword_search_term.h" 29 #include "components/history/core/browser/keyword_search_term.h"
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread.h"
32 #include "content/public/test/test_utils.h" 32 #include "content/public/test/test_utils.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "third_party/skia/include/core/SkBitmap.h"
34 35
35 using base::Time; 36 using base::Time;
36 using base::TimeDelta; 37 using base::TimeDelta;
37 using base::UTF8ToUTF16; 38 using base::UTF8ToUTF16;
38 using content::BrowserThread; 39 using content::BrowserThread;
39 40
40 namespace history { 41 namespace history {
41 42
42 namespace { 43 namespace {
43 44
44 struct BookmarkCacheRow { 45 struct BookmarkCacheRow {
45 public: 46 public:
46 BookmarkCacheRow() 47 BookmarkCacheRow()
47 : url_id_(0), 48 : url_id_(0),
48 bookmark_(false), 49 bookmark_(false),
49 favicon_id_(0) { 50 favicon_id_(0) {
50 } 51 }
51 URLID url_id_; 52 URLID url_id_;
52 Time create_time_; 53 Time create_time_;
53 Time last_visit_time_; 54 Time last_visit_time_;
54 bool bookmark_; 55 bool bookmark_;
55 favicon_base::FaviconID favicon_id_; 56 favicon_base::FaviconID favicon_id_;
56 }; 57 };
57 58
59 // Creates a 16x16 bitmap.
60 SkBitmap CreateBitmap() {
61 SkBitmap bitmap;
62 bitmap.allocN32Pixels(16, 16);
63 bitmap.eraseColor(SK_ColorBLUE);
64 return bitmap;
65 }
66
58 } // namespace 67 } // namespace
59 68
60 class AndroidProviderBackendDelegate : public HistoryBackend::Delegate { 69 class AndroidProviderBackendDelegate : public HistoryBackend::Delegate {
61 public: 70 public:
62 AndroidProviderBackendDelegate() {} 71 AndroidProviderBackendDelegate() {}
63 72
64 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {} 73 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {}
65 virtual void SetInMemoryBackend( 74 virtual void SetInMemoryBackend(
66 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE {} 75 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE {}
67 virtual void BroadcastNotifications( 76 virtual void BroadcastNotifications(
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED); 258 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED);
250 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED); 259 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED);
251 URLRow url_row; 260 URLRow url_row;
252 261
253 ASSERT_TRUE(history_backend->GetURL(url1, &url_row)); 262 ASSERT_TRUE(history_backend->GetURL(url1, &url_row));
254 url_id1 = url_row.id(); 263 url_id1 = url_row.id();
255 ASSERT_TRUE(history_backend->GetURL(url2, &url_row)); 264 ASSERT_TRUE(history_backend->GetURL(url2, &url_row));
256 url_id2 = url_row.id(); 265 url_id2 = url_row.id();
257 266
258 // Set favicon to url2. 267 // Set favicon to url2.
259 std::vector<unsigned char> data; 268 std::vector<SkBitmap> bitmaps(1u, CreateBitmap());
260 data.push_back('1'); 269 history_backend->SetFavicons(url2, favicon_base::FAVICON, GURL(), bitmaps);
261 favicon_base::FaviconRawBitmapData bitmap_data_element;
262 bitmap_data_element.bitmap_data = new base::RefCountedBytes(data);
263 bitmap_data_element.pixel_size = gfx::Size();
264 bitmap_data_element.icon_url = GURL();
265 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
266 favicon_bitmap_data.push_back(bitmap_data_element);
267
268 history_backend->SetFavicons(
269 url2, favicon_base::FAVICON, favicon_bitmap_data);
270 history_backend->Closing(); 270 history_backend->Closing();
271 } 271 }
272 272
273 // The history_db_name and thumbnail_db_name files should be created by 273 // The history_db_name and thumbnail_db_name files should be created by
274 // HistoryBackend. We need to open the same database files. 274 // HistoryBackend. We need to open the same database files.
275 ASSERT_TRUE(base::PathExists(history_db_name_)); 275 ASSERT_TRUE(base::PathExists(history_db_name_));
276 ASSERT_TRUE(base::PathExists(thumbnail_db_name_)); 276 ASSERT_TRUE(base::PathExists(thumbnail_db_name_));
277 277
278 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 278 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
279 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_)); 279 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED); 396 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED);
397 397
398 history::URLRows url_rows(2u); 398 history::URLRows url_rows(2u);
399 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0])); 399 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0]));
400 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1])); 400 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1]));
401 url_rows[0].set_title(title1); 401 url_rows[0].set_title(title1);
402 url_rows[1].set_title(title2); 402 url_rows[1].set_title(title2);
403 ASSERT_EQ(2u, history_backend->UpdateURLs(url_rows)); 403 ASSERT_EQ(2u, history_backend->UpdateURLs(url_rows));
404 404
405 // Set favicon to url2. 405 // Set favicon to url2.
406 std::vector<unsigned char> data; 406 std::vector<SkBitmap> bitmaps(1u, CreateBitmap());
407 data.push_back('1'); 407 history_backend->SetFavicons(url2, favicon_base::FAVICON, GURL(), bitmaps);
408 favicon_base::FaviconRawBitmapData bitmap_data_element;
409 bitmap_data_element.bitmap_data = new base::RefCountedBytes(data);
410 bitmap_data_element.pixel_size = gfx::Size();
411 bitmap_data_element.icon_url = GURL();
412 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
413 favicon_bitmap_data.push_back(bitmap_data_element);
414
415 history_backend->SetFavicons(
416 url2, favicon_base::FAVICON, favicon_bitmap_data);
417 history_backend->Closing(); 408 history_backend->Closing();
418 } 409 }
419 410
420 // The history_db_name and thumbnail_db_name files should be created by 411 // The history_db_name and thumbnail_db_name files should be created by
421 // HistoryBackend. We need to open the same database files. 412 // HistoryBackend. We need to open the same database files.
422 ASSERT_TRUE(base::PathExists(history_db_name_)); 413 ASSERT_TRUE(base::PathExists(history_db_name_));
423 ASSERT_TRUE(base::PathExists(thumbnail_db_name_)); 414 ASSERT_TRUE(base::PathExists(thumbnail_db_name_));
424 415
425 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 416 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
426 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_)); 417 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_));
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 URLRow url_row; 1833 URLRow url_row;
1843 1834
1844 history::URLRows url_rows(2u); 1835 history::URLRows url_rows(2u);
1845 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0])); 1836 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0]));
1846 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1])); 1837 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1]));
1847 url_rows[0].set_title(title1); 1838 url_rows[0].set_title(title1);
1848 url_rows[1].set_title(title2); 1839 url_rows[1].set_title(title2);
1849 ASSERT_EQ(2u, history_backend->UpdateURLs(url_rows)); 1840 ASSERT_EQ(2u, history_backend->UpdateURLs(url_rows));
1850 1841
1851 // Set favicon to url2. 1842 // Set favicon to url2.
1852 std::vector<unsigned char> data; 1843 std::vector<SkBitmap> bitmaps(1u, CreateBitmap());
1853 data.push_back('1'); 1844 history_backend->SetFavicons(url2, favicon_base::FAVICON, GURL(), bitmaps);
1854 favicon_base::FaviconRawBitmapData bitmap_data_element;
1855 bitmap_data_element.bitmap_data = new base::RefCountedBytes(data);
1856 bitmap_data_element.pixel_size = gfx::Size();
1857 bitmap_data_element.icon_url = GURL();
1858 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1859 favicon_bitmap_data.push_back(bitmap_data_element);
1860
1861 history_backend->SetFavicons(
1862 url2, favicon_base::FAVICON, favicon_bitmap_data);
1863 history_backend->Closing(); 1845 history_backend->Closing();
1864 } 1846 }
1865 1847
1866 // The history_db_name and thumbnail_db_name files should be created by 1848 // The history_db_name and thumbnail_db_name files should be created by
1867 // HistoryBackend. We need to open the same database files. 1849 // HistoryBackend. We need to open the same database files.
1868 ASSERT_TRUE(base::PathExists(history_db_name_)); 1850 ASSERT_TRUE(base::PathExists(history_db_name_));
1869 ASSERT_TRUE(base::PathExists(thumbnail_db_name_)); 1851 ASSERT_TRUE(base::PathExists(thumbnail_db_name_));
1870 1852
1871 // Only creates the history database 1853 // Only creates the history database
1872 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 1854 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 update_args, &update_count)); 2108 update_args, &update_count));
2127 // Verify notifications. 2109 // Verify notifications.
2128 EXPECT_FALSE(delegate_.deleted_details()); 2110 EXPECT_FALSE(delegate_.deleted_details());
2129 ASSERT_TRUE(delegate_.modified_details()); 2111 ASSERT_TRUE(delegate_.modified_details());
2130 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 2112 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
2131 // No favicon will be updated as thumbnail database is missing. 2113 // No favicon will be updated as thumbnail database is missing.
2132 EXPECT_FALSE(delegate_.favicon_details()); 2114 EXPECT_FALSE(delegate_.favicon_details());
2133 } 2115 }
2134 2116
2135 } // namespace history 2117 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_service.cc ('k') | chrome/browser/history/history_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698