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

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

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

Powered by Google App Engine
This is Rietveld 408576698