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

Side by Side Diff: chrome/browser/webdata/web_apps_table_unittest.cc

Issue 382703002: Remove unused SQLLite tables from WebData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 2 Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/files/scoped_temp_dir.h"
6 #include "base/path_service.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/time/time.h"
9 #include "chrome/browser/webdata/web_apps_table.h"
10 #include "components/webdata/common/web_database.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "url/gurl.h"
14
15 using base::Time;
16
17 class WebAppsTableTest : public testing::Test {
18 public:
19 WebAppsTableTest() {}
20 virtual ~WebAppsTableTest() {}
21
22 protected:
23 virtual void SetUp() {
24 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
25 file_ = temp_dir_.path().AppendASCII("TestWebDatabase");
26
27 table_.reset(new WebAppsTable);
28 db_.reset(new WebDatabase);
29 db_->AddTable(table_.get());
30 ASSERT_EQ(sql::INIT_OK, db_->Init(file_));
31 }
32
33 base::FilePath file_;
34 base::ScopedTempDir temp_dir_;
35 scoped_ptr<WebAppsTable> table_;
36 scoped_ptr<WebDatabase> db_;
37
38 private:
39 DISALLOW_COPY_AND_ASSIGN(WebAppsTableTest);
40 };
41
42
43 TEST_F(WebAppsTableTest, WebAppHasAllImages) {
44 GURL url("http://google.com/");
45
46 // Initial value for unknown web app should be false.
47 EXPECT_FALSE(table_->GetWebAppHasAllImages(url));
48
49 // Set the value and make sure it took.
50 EXPECT_TRUE(table_->SetWebAppHasAllImages(url, true));
51 EXPECT_TRUE(table_->GetWebAppHasAllImages(url));
52
53 // Remove the app and make sure value reverts to default.
54 EXPECT_TRUE(table_->RemoveWebApp(url));
55 EXPECT_FALSE(table_->GetWebAppHasAllImages(url));
56 }
57
58 TEST_F(WebAppsTableTest, WebAppImages) {
59 GURL url("http://google.com/");
60
61 // Web app should initially have no images.
62 std::vector<SkBitmap> images;
63 ASSERT_TRUE(table_->GetWebAppImages(url, &images));
64 ASSERT_EQ(0U, images.size());
65
66 // Add an image.
67 SkBitmap image;
68 image.allocN32Pixels(16, 16);
69 image.eraseColor(SK_ColorBLACK);
70 ASSERT_TRUE(table_->SetWebAppImage(url, image));
71
72 // Make sure we get the image back.
73 ASSERT_TRUE(table_->GetWebAppImages(url, &images));
74 ASSERT_EQ(1U, images.size());
75 ASSERT_EQ(16, images[0].width());
76 ASSERT_EQ(16, images[0].height());
77
78 // Add another 16x16 image and make sure it replaces the original.
79 image.allocN32Pixels(16, 16);
80 image.eraseColor(SK_ColorBLACK);
81
82 // Set some random pixels so that we can identify the image. We don't use
83 // transparent images because of pre-multiplication rounding errors.
84 SkColor test_pixel_1 = 0xffccbbaa;
85 SkColor test_pixel_2 = 0xffaabbaa;
86 SkColor test_pixel_3 = 0xff339966;
87 image.getAddr32(0, 1)[0] = test_pixel_1;
88 image.getAddr32(0, 1)[1] = test_pixel_2;
89 image.getAddr32(0, 1)[2] = test_pixel_3;
90
91 ASSERT_TRUE(table_->SetWebAppImage(url, image));
92 images.clear();
93 ASSERT_TRUE(table_->GetWebAppImages(url, &images));
94 ASSERT_EQ(1U, images.size());
95 ASSERT_EQ(16, images[0].width());
96 ASSERT_EQ(16, images[0].height());
97 images[0].lockPixels();
98 ASSERT_TRUE(images[0].getPixels() != NULL);
99 ASSERT_EQ(test_pixel_1, images[0].getAddr32(0, 1)[0]);
100 ASSERT_EQ(test_pixel_2, images[0].getAddr32(0, 1)[1]);
101 ASSERT_EQ(test_pixel_3, images[0].getAddr32(0, 1)[2]);
102 images[0].unlockPixels();
103
104 // Add another image at a bigger size.
105 image.allocN32Pixels(32, 32);
106 image.eraseColor(SK_ColorBLACK);
107 ASSERT_TRUE(table_->SetWebAppImage(url, image));
108
109 // Make sure we get both images back.
110 images.clear();
111 ASSERT_TRUE(table_->GetWebAppImages(url, &images));
112 ASSERT_EQ(2U, images.size());
113 if (images[0].width() == 16) {
114 ASSERT_EQ(16, images[0].width());
115 ASSERT_EQ(16, images[0].height());
116 ASSERT_EQ(32, images[1].width());
117 ASSERT_EQ(32, images[1].height());
118 } else {
119 ASSERT_EQ(32, images[0].width());
120 ASSERT_EQ(32, images[0].height());
121 ASSERT_EQ(16, images[1].width());
122 ASSERT_EQ(16, images[1].height());
123 }
124 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_apps_table.cc ('k') | chrome/browser/webdata/web_data_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698