summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 22:54:32 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 22:54:32 +0000
commit292f0a46a5d8444073674cd16344839581769baa (patch)
treebeb98046f773b8e94810bd0b92d6b1e3c2dcc01d
parentf10af50f5665accf416d7d4e2f40b7f4cd5027af (diff)
downloadchromium_src-292f0a46a5d8444073674cd16344839581769baa.zip
chromium_src-292f0a46a5d8444073674cd16344839581769baa.tar.gz
chromium_src-292f0a46a5d8444073674cd16344839581769baa.tar.bz2
Merge 37722 - Don't store IDR ids in ThemePack files as they change whenever the grd is modified.
Instead, add an association table at the top of browser_theme_pack.cc that maps the JSON string name and IDR# to a stable constant that won't change between releases. The ThemePack version number has been bumped to two, forcing a rebuild. BUG=33416 TEST=none Review URL: http://codereview.chromium.org/548207 TBR=erg@google.com git-svn-id: svn://svn.chromium.org/chrome/branches/307/src@37760 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_theme_pack.cc287
-rw-r--r--chrome/browser/browser_theme_pack_unittest.cc48
-rw-r--r--chrome/test/data/profiles/complex_theme/Default/Extensions/mblmlcbknbnfebdfjnolmcapmdofhmme/1.1/Cached Theme.pakbin1233037 -> 1233013 bytes
3 files changed, 257 insertions, 78 deletions
diff --git a/chrome/browser/browser_theme_pack.cc b/chrome/browser/browser_theme_pack.cc
index b6e3fd9..275bbbb 100644
--- a/chrome/browser/browser_theme_pack.cc
+++ b/chrome/browser/browser_theme_pack.cc
@@ -30,7 +30,7 @@ namespace {
// Version number of the current theme pack. We just throw out and rebuild
// theme packs that aren't int-equal to this.
-const int kThemePackVersion = 1;
+const int kThemePackVersion = 2;
// IDs that are in the DataPack won't clash with the positive integer
// int32_t. kHeaderID should always have the maximum value because we want the
@@ -51,6 +51,139 @@ const int kDisplayPropertySize = 3;
// OpaqueBrowserFrameView.
const int kRestoredTabVerticalOffset = 15;
+// Persistent constants for the main images that we need. These have the same
+// names as their IDR_* counterparts but these values will always stay the
+// same.
+const int PRS_THEME_FRAME = 1;
+const int PRS_THEME_FRAME_INACTIVE = 2;
+const int PRS_THEME_FRAME_INCOGNITO = 3;
+const int PRS_THEME_FRAME_INCOGNITO_INACTIVE = 4;
+const int PRS_THEME_TOOLBAR = 5;
+const int PRS_THEME_TAB_BACKGROUND = 6;
+const int PRS_THEME_TAB_BACKGROUND_INCOGNITO = 7;
+const int PRS_THEME_TAB_BACKGROUND_V = 8;
+const int PRS_THEME_NTP_BACKGROUND = 9;
+const int PRS_THEME_FRAME_OVERLAY = 10;
+const int PRS_THEME_FRAME_OVERLAY_INACTIVE = 11;
+const int PRS_THEME_BUTTON_BACKGROUND = 12;
+const int PRS_THEME_NTP_ATTRIBUTION = 13;
+const int PRS_THEME_WINDOW_CONTROL_BACKGROUND = 14;
+
+struct PersistingImagesTable {
+ // A non-changing integer ID meant to be saved in theme packs. This ID must
+ // not change between versions of chrome.
+ int persistent_id;
+
+ // The IDR that depends on the whims of GRIT and therefore changes whenever
+ // someone adds a new resource.
+ int idr_id;
+
+ // String to check for when parsing theme manifests or NULL if this isn't
+ // supposed to be changeable by the user.
+ const char* key;
+};
+
+// IDR_* resource names change whenever new resources are added; use persistent
+// IDs when storing to a cached pack.
+PersistingImagesTable kPersistingImages[] = {
+ { PRS_THEME_FRAME, IDR_THEME_FRAME,
+ "theme_frame" },
+ { PRS_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INACTIVE,
+ "theme_frame_inactive" },
+ { PRS_THEME_FRAME_INCOGNITO, IDR_THEME_FRAME_INCOGNITO,
+ "theme_frame_incognito" },
+ { PRS_THEME_FRAME_INCOGNITO_INACTIVE, IDR_THEME_FRAME_INCOGNITO_INACTIVE,
+ "theme_frame_incognito_inactive" },
+ { PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR,
+ "theme_toolbar" },
+ { PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND,
+ "theme_tab_background" },
+ { PRS_THEME_TAB_BACKGROUND_INCOGNITO, IDR_THEME_TAB_BACKGROUND_INCOGNITO,
+ "theme_tab_background_incognito" },
+ { PRS_THEME_TAB_BACKGROUND_V, IDR_THEME_TAB_BACKGROUND_V,
+ "theme_tab_background_v"},
+ { PRS_THEME_NTP_BACKGROUND, IDR_THEME_NTP_BACKGROUND,
+ "theme_ntp_background" },
+ { PRS_THEME_FRAME_OVERLAY, IDR_THEME_FRAME_OVERLAY,
+ "theme_frame_overlay" },
+ { PRS_THEME_FRAME_OVERLAY_INACTIVE, IDR_THEME_FRAME_OVERLAY_INACTIVE,
+ "theme_frame_overlay_inactive" },
+ { PRS_THEME_BUTTON_BACKGROUND, IDR_THEME_BUTTON_BACKGROUND,
+ "theme_button_background" },
+ { PRS_THEME_NTP_ATTRIBUTION, IDR_THEME_NTP_ATTRIBUTION,
+ "theme_ntp_attribution" },
+ { PRS_THEME_WINDOW_CONTROL_BACKGROUND, IDR_THEME_WINDOW_CONTROL_BACKGROUND,
+ "theme_window_control_background"},
+
+ // The rest of these entries have no key because they can't be overridden
+ // from the json manifest.
+ { 15, IDR_BACK, NULL },
+ { 16, IDR_BACK_D, NULL },
+ { 17, IDR_BACK_H, NULL },
+ { 18, IDR_BACK_P, NULL },
+ { 19, IDR_FORWARD, NULL },
+ { 20, IDR_FORWARD_D, NULL },
+ { 21, IDR_FORWARD_H, NULL },
+ { 22, IDR_FORWARD_P, NULL },
+ { 23, IDR_RELOAD, NULL },
+ { 24, IDR_RELOAD_H, NULL },
+ { 25, IDR_RELOAD_P, NULL },
+ { 26, IDR_HOME, NULL },
+ { 27, IDR_HOME_H, NULL },
+ { 28, IDR_HOME_P, NULL },
+ { 29, IDR_STAR, NULL },
+ { 30, IDR_STAR_NOBORDER, NULL },
+ { 31, IDR_STAR_NOBORDER_CENTER, NULL },
+ { 32, IDR_STAR_D, NULL },
+ { 33, IDR_STAR_H, NULL },
+ { 34, IDR_STAR_P, NULL },
+ { 35, IDR_STARRED, NULL },
+ { 36, IDR_STARRED_NOBORDER, NULL },
+ { 37, IDR_STARRED_NOBORDER_CENTER, NULL },
+ { 38, IDR_STARRED_H, NULL },
+ { 39, IDR_STARRED_P, NULL },
+ { 40, IDR_GO, NULL },
+ { 41, IDR_GO_NOBORDER, NULL },
+ { 42, IDR_GO_NOBORDER_CENTER, NULL },
+ { 43, IDR_GO_H, NULL },
+ { 44, IDR_GO_P, NULL },
+ { 45, IDR_STOP, NULL },
+ { 46, IDR_STOP_NOBORDER, NULL },
+ { 47, IDR_STOP_NOBORDER_CENTER, NULL },
+ { 48, IDR_STOP_H, NULL },
+ { 49, IDR_STOP_P, NULL },
+ { 50, IDR_MENU_BOOKMARK, NULL },
+ { 51, IDR_MENU_PAGE, NULL },
+ { 52, IDR_MENU_PAGE_RTL, NULL },
+ { 53, IDR_MENU_CHROME, NULL },
+ { 54, IDR_MENU_CHROME_RTL, NULL },
+ { 55, IDR_MENU_DROPARROW, NULL },
+ { 56, IDR_THROBBER, NULL },
+ { 57, IDR_THROBBER_WAITING, NULL },
+ { 58, IDR_THROBBER_LIGHT, NULL },
+ { 59, IDR_LOCATIONBG, NULL }
+};
+
+const int GetPersistentIDByName(const std::string& key) {
+ for (size_t i = 0; i < arraysize(kPersistingImages); ++i) {
+ if (kPersistingImages[i].key != NULL &&
+ base::strcasecmp(key.c_str(), kPersistingImages[i].key) == 0) {
+ return kPersistingImages[i].persistent_id;
+ }
+ }
+
+ return -1;
+}
+
+const int GetPersistentIDByIDR(int idr) {
+ for (size_t i = 0; i < arraysize(kPersistingImages); ++i) {
+ if (kPersistingImages[i].idr_id == idr) {
+ return kPersistingImages[i].persistent_id;
+ }
+ }
+
+ return -1;
+}
struct StringToIntTable {
const char* key;
@@ -130,32 +263,33 @@ struct IntToIntTable {
// Mapping used in GenerateFrameImages() to associate frame images with the
// tint ID that should maybe be applied to it.
IntToIntTable kFrameTintMap[] = {
- { IDR_THEME_FRAME, BrowserThemeProvider::TINT_FRAME },
- { IDR_THEME_FRAME_INACTIVE, BrowserThemeProvider::TINT_FRAME_INACTIVE },
- { IDR_THEME_FRAME_OVERLAY, BrowserThemeProvider::TINT_FRAME },
- { IDR_THEME_FRAME_OVERLAY_INACTIVE,
+ { PRS_THEME_FRAME, BrowserThemeProvider::TINT_FRAME },
+ { PRS_THEME_FRAME_INACTIVE, BrowserThemeProvider::TINT_FRAME_INACTIVE },
+ { PRS_THEME_FRAME_OVERLAY, BrowserThemeProvider::TINT_FRAME },
+ { PRS_THEME_FRAME_OVERLAY_INACTIVE,
BrowserThemeProvider::TINT_FRAME_INACTIVE },
- { IDR_THEME_FRAME_INCOGNITO, BrowserThemeProvider::TINT_FRAME_INCOGNITO },
- { IDR_THEME_FRAME_INCOGNITO_INACTIVE,
+ { PRS_THEME_FRAME_INCOGNITO, BrowserThemeProvider::TINT_FRAME_INCOGNITO },
+ { PRS_THEME_FRAME_INCOGNITO_INACTIVE,
BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE }
};
// Mapping used in GenerateTabBackgroundImages() to associate what frame image
// goes with which tab background.
IntToIntTable kTabBackgroundMap[] = {
- { IDR_THEME_TAB_BACKGROUND, IDR_THEME_FRAME },
- { IDR_THEME_TAB_BACKGROUND_INCOGNITO, IDR_THEME_FRAME_INCOGNITO }
+ { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME },
+ { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }
};
// A list of images that don't need tinting or any other modification and can
-// be byte-copied directly into the finished DataPack. This should contain all
-// themeable image IDs that aren't in kFrameTintMap or kTabBackgroundMap.
+// be byte-copied directly into the finished DataPack. This should contain the
+// persistent IDs for all themeable image IDs that aren't in kFrameTintMap or
+// kTabBackgroundMap.
const int kPreloadIDs[] = {
- IDR_THEME_TOOLBAR,
- IDR_THEME_NTP_BACKGROUND,
- IDR_THEME_BUTTON_BACKGROUND,
- IDR_THEME_NTP_ATTRIBUTION,
- IDR_THEME_WINDOW_CONTROL_BACKGROUND
+ PRS_THEME_TOOLBAR,
+ PRS_THEME_NTP_BACKGROUND,
+ PRS_THEME_BUTTON_BACKGROUND,
+ PRS_THEME_NTP_ATTRIBUTION,
+ PRS_THEME_WINDOW_CONTROL_BACKGROUND
};
// Returns a piece of memory with the contents of the file |path|.
@@ -261,8 +395,10 @@ scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack(
pack->header_ = reinterpret_cast<BrowserThemePackHeader*>(const_cast<char*>(
pointer.data()));
- if (pack->header_->version != kThemePackVersion)
+ if (pack->header_->version != kThemePackVersion) {
+ DLOG(ERROR) << "BuildFromDataPack failure! Version mismatch!";
return NULL;
+ }
// TODO(erg): Check endianess once DataPack works on the other endian.
std::string theme_id(reinterpret_cast<char*>(pack->header_->theme_id),
Extension::kIdSize);
@@ -354,22 +490,24 @@ bool BrowserThemePack::GetDisplayProperty(int id, int* result) const {
return false;
}
-SkBitmap* BrowserThemePack::GetBitmapNamed(int id) const {
+SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const {
+ int prs_id = GetPersistentIDByIDR(idr_id);
+
// Check our cache of prepared images, first.
- ImageCache::const_iterator image_iter = prepared_images_.find(id);
+ ImageCache::const_iterator image_iter = prepared_images_.find(prs_id);
if (image_iter != prepared_images_.end())
return image_iter->second;
// Check if we've already loaded this image.
- image_iter = loaded_images_.find(id);
+ image_iter = loaded_images_.find(prs_id);
if (image_iter != loaded_images_.end())
return image_iter->second;
scoped_refptr<RefCountedMemory> memory;
if (data_pack_.get()) {
- memory = data_pack_->GetStaticMemory(id);
+ memory = data_pack_->GetStaticMemory(prs_id);
} else {
- RawImages::const_iterator it = image_memory_.find(id);
+ RawImages::const_iterator it = image_memory_.find(prs_id);
if (it != image_memory_.end()) {
memory = it->second;
}
@@ -380,13 +518,13 @@ SkBitmap* BrowserThemePack::GetBitmapNamed(int id) const {
SkBitmap bitmap;
if (!gfx::PNGCodec::Decode(memory->front(), memory->size(),
&bitmap)) {
- NOTREACHED() << "Unable to decode theme image resource " << id
+ NOTREACHED() << "Unable to decode theme image resource " << idr_id
<< " from saved DataPack.";
return NULL;
}
SkBitmap* ret = new SkBitmap(bitmap);
- loaded_images_[id] = ret;
+ loaded_images_[prs_id] = ret;
return ret;
}
@@ -394,28 +532,35 @@ SkBitmap* BrowserThemePack::GetBitmapNamed(int id) const {
return NULL;
}
-RefCountedMemory* BrowserThemePack::GetRawData(int id) const {
+RefCountedMemory* BrowserThemePack::GetRawData(int idr_id) const {
RefCountedMemory* memory = NULL;
+ int prs_id = GetPersistentIDByIDR(idr_id);
- if (data_pack_.get()) {
- memory = data_pack_->GetStaticMemory(id);
- } else {
- RawImages::const_iterator it = image_memory_.find(id);
- if (it != image_memory_.end()) {
- memory = it->second;
+ if (prs_id != -1) {
+ if (data_pack_.get()) {
+ memory = data_pack_->GetStaticMemory(prs_id);
+ } else {
+ RawImages::const_iterator it = image_memory_.find(prs_id);
+ if (it != image_memory_.end()) {
+ memory = it->second;
+ }
}
}
return memory;
}
-bool BrowserThemePack::HasCustomImage(int id) const {
+bool BrowserThemePack::HasCustomImage(int idr_id) const {
+ int prs_id = GetPersistentIDByIDR(idr_id);
+ if (prs_id == -1)
+ return false;
+
if (data_pack_.get()) {
base::StringPiece ignored;
- return data_pack_->GetStringPiece(id, &ignored);
+ return data_pack_->GetStringPiece(prs_id, &ignored);
} else {
- return prepared_images_.count(id) > 0 ||
- image_memory_.count(id) > 0;
+ return prepared_images_.count(prs_id) > 0 ||
+ image_memory_.count(prs_id) > 0;
}
}
@@ -672,7 +817,7 @@ void BrowserThemePack::ParseImageNamesFromJSON(
iter != images_value->end_keys(); ++iter) {
std::string val;
if (images_value->GetString(*iter, &val)) {
- int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter));
+ int id = GetPersistentIDByName(WideToUTF8(*iter));
if (id != -1)
(*file_paths)[id] = images_path.AppendASCII(val);
}
@@ -720,33 +865,33 @@ void BrowserThemePack::GenerateFrameImages(ImageCache* bitmaps) const {
ImageCache temp_output;
for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) {
- int id = kFrameTintMap[i].key;
+ int prs_id = kFrameTintMap[i].key;
scoped_ptr<SkBitmap> frame;
// If there's no frame image provided for the specified id, then load
// the default provided frame. If that's not provided, skip this whole
// thing and just use the default images.
- int base_id;
-
- if (id == IDR_THEME_FRAME_INCOGNITO_INACTIVE) {
- base_id = bitmaps->count(IDR_THEME_FRAME_INCOGNITO) ?
- IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME;
- } else if (id == IDR_THEME_FRAME_OVERLAY_INACTIVE) {
- base_id = IDR_THEME_FRAME_OVERLAY;
- } else if (id == IDR_THEME_FRAME_INACTIVE) {
- base_id = IDR_THEME_FRAME;
- } else if (id == IDR_THEME_FRAME_INCOGNITO &&
- !bitmaps->count(IDR_THEME_FRAME_INCOGNITO)) {
- base_id = IDR_THEME_FRAME;
+ int prs_base_id;
+
+ if (prs_id == PRS_THEME_FRAME_INCOGNITO_INACTIVE) {
+ prs_base_id = bitmaps->count(PRS_THEME_FRAME_INCOGNITO) ?
+ PRS_THEME_FRAME_INCOGNITO : PRS_THEME_FRAME;
+ } else if (prs_id == PRS_THEME_FRAME_OVERLAY_INACTIVE) {
+ prs_base_id = PRS_THEME_FRAME_OVERLAY;
+ } else if (prs_id == PRS_THEME_FRAME_INACTIVE) {
+ prs_base_id = PRS_THEME_FRAME;
+ } else if (prs_id == PRS_THEME_FRAME_INCOGNITO &&
+ !bitmaps->count(PRS_THEME_FRAME_INCOGNITO)) {
+ prs_base_id = PRS_THEME_FRAME;
} else {
- base_id = id;
+ prs_base_id = prs_id;
}
- if (bitmaps->count(id)) {
- frame.reset(new SkBitmap(*(*bitmaps)[id]));
- } else if (base_id != id && bitmaps->count(base_id)) {
- frame.reset(new SkBitmap(*(*bitmaps)[base_id]));
- } else if (base_id == IDR_THEME_FRAME_OVERLAY &&
- bitmaps->count(IDR_THEME_FRAME)) {
+ if (bitmaps->count(prs_id)) {
+ frame.reset(new SkBitmap(*(*bitmaps)[prs_id]));
+ } else if (prs_base_id != prs_id && bitmaps->count(prs_base_id)) {
+ frame.reset(new SkBitmap(*(*bitmaps)[prs_base_id]));
+ } else if (prs_base_id == PRS_THEME_FRAME_OVERLAY &&
+ bitmaps->count(PRS_THEME_FRAME)) {
// If there is no theme overlay, don't tint the default frame,
// because it will overwrite the custom frame image when we cache and
// reload from disk.
@@ -758,7 +903,7 @@ void BrowserThemePack::GenerateFrameImages(ImageCache* bitmaps) const {
}
if (frame.get()) {
- temp_output[id] = new SkBitmap(
+ temp_output[prs_id] = new SkBitmap(
SkBitmapOperations::CreateHSLShiftedBitmap(
*frame, GetTintInternal(kFrameTintMap[i].value)));
}
@@ -772,12 +917,17 @@ void BrowserThemePack::GenerateTintedButtons(
ImageCache* processed_bitmaps) const {
if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- const std::set<int>& ids =
+ const std::set<int>& idr_ids =
BrowserThemeProvider::GetTintableToolbarButtons();
- for (std::set<int>::const_iterator it = ids.begin(); it != ids.end();
- ++it) {
+ for (std::set<int>::const_iterator it = idr_ids.begin();
+ it != idr_ids.end(); ++it) {
+ int prs_id = GetPersistentIDByIDR(*it);
+
+ // Fetch the image by IDR...
scoped_ptr<SkBitmap> button(new SkBitmap(*rb.GetBitmapNamed(*it)));
- (*processed_bitmaps)[*it] = new SkBitmap(
+
+ // but save a version with the persistent ID.
+ (*processed_bitmaps)[prs_id] = new SkBitmap(
SkBitmapOperations::CreateHSLShiftedBitmap(*button, button_tint));
}
}
@@ -786,22 +936,23 @@ void BrowserThemePack::GenerateTintedButtons(
void BrowserThemePack::GenerateTabBackgroundImages(ImageCache* bitmaps) const {
ImageCache temp_output;
for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) {
- int id = kTabBackgroundMap[i].key;
- int base_id = kTabBackgroundMap[i].value;
+ int prs_id = kTabBackgroundMap[i].key;
+ int prs_base_id = kTabBackgroundMap[i].value;
// We only need to generate the background tab images if we were provided
- // with a IDR_THEME_FRAME.
- ImageCache::const_iterator it = bitmaps->find(base_id);
+ // with a PRS_THEME_FRAME.
+ ImageCache::const_iterator it = bitmaps->find(prs_base_id);
if (it != bitmaps->end()) {
SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap(
*(it->second), GetTintInternal(
BrowserThemeProvider::TINT_BACKGROUND_TAB));
- int vertical_offset = bitmaps->count(id) ? kRestoredTabVerticalOffset : 0;
+ int vertical_offset = bitmaps->count(prs_id)
+ ? kRestoredTabVerticalOffset : 0;
SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap(
bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height()));
// If they've provided a custom image, overlay it.
- ImageCache::const_iterator overlay_it = bitmaps->find(id);
+ ImageCache::const_iterator overlay_it = bitmaps->find(prs_id);
if (overlay_it != bitmaps->end()) {
SkBitmap* overlay = overlay_it->second;
SkCanvas canvas(*bg_tab);
@@ -809,7 +960,7 @@ void BrowserThemePack::GenerateTabBackgroundImages(ImageCache* bitmaps) const {
canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL);
}
- temp_output[id] = bg_tab;
+ temp_output[prs_id] = bg_tab;
}
}
diff --git a/chrome/browser/browser_theme_pack_unittest.cc b/chrome/browser/browser_theme_pack_unittest.cc
index 7d780f2..691eda8 100644
--- a/chrome/browser/browser_theme_pack_unittest.cc
+++ b/chrome/browser/browser_theme_pack_unittest.cc
@@ -105,13 +105,17 @@ class BrowserThemePackTest : public ::testing::Test {
theme_pack_->BuildDisplayPropertiesFromJSON(value);
}
- void ParseImageNames(const std::string& json,
+ void ParseImageNamesJSON(const std::string& json,
std::map<int, FilePath>* out_file_paths) {
scoped_ptr<Value> value(base::JSONReader::Read(json, false));
ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
- theme_pack_->ParseImageNamesFromJSON(
- static_cast<DictionaryValue*>(value.get()),
- FilePath(), out_file_paths);
+ ParseImageNamesDictionary(static_cast<DictionaryValue*>(value.get()),
+ out_file_paths);
+ }
+
+ void ParseImageNamesDictionary(DictionaryValue* value,
+ std::map<int, FilePath>* out_file_paths) {
+ theme_pack_->ParseImageNamesFromJSON(value, FilePath(), out_file_paths);
}
FilePath GetStarGazingPath() {
@@ -156,7 +160,14 @@ class BrowserThemePackTest : public ::testing::Test {
BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT, &val));
EXPECT_EQ(BrowserThemeProvider::ALIGN_TOP, val);
+ // Every theme should have the following images, because they need to be
+ // tinted.
EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME));
+ EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INACTIVE));
+ EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO));
+ EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE));
+ EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND));
+ EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_INCOGNITO));
// Make sure we don't have phantom data.
EXPECT_FALSE(pack->GetColor(BrowserThemeProvider::COLOR_CONTROL_BACKGROUND,
@@ -270,16 +281,28 @@ TEST_F(BrowserThemePackTest, CanReadDisplayProperties) {
}
TEST_F(BrowserThemePackTest, CanParsePaths) {
- std::string tint_json = "{ \"theme_button_background\": \"one\", "
+ std::string path_json = "{ \"theme_button_background\": \"one\", "
" \"theme_toolbar\": \"two\" }";
std::map<int, FilePath> out_file_paths;
- ParseImageNames(tint_json, &out_file_paths);
+ ParseImageNamesJSON(path_json, &out_file_paths);
EXPECT_EQ(2u, out_file_paths.size());
- EXPECT_TRUE(FilePath(FILE_PATH_LITERAL("one")) == out_file_paths[
- ThemeResourcesUtil::GetId("theme_button_background")]);
- EXPECT_TRUE(FilePath(FILE_PATH_LITERAL("two")) ==
- out_file_paths[ThemeResourcesUtil::GetId("theme_toolbar")]);
+ // "12" and "5" are internal constants to BrowserThemePack and are
+ // PRS_THEME_BUTTON_BACKGROUND and PRS_THEME_TOOLBAR, but they are
+ // implementation details that shouldn't be exported.
+ EXPECT_TRUE(FilePath(FILE_PATH_LITERAL("one")) == out_file_paths[12]);
+ EXPECT_TRUE(FilePath(FILE_PATH_LITERAL("two")) == out_file_paths[5]);
+}
+
+TEST_F(BrowserThemePackTest, InvalidPathNames) {
+ std::string path_json = "{ \"wrong\": [1], "
+ " \"theme_button_background\": \"one\", "
+ " \"not_a_thing\": \"blah\" }";
+ std::map<int, FilePath> out_file_paths;
+ ParseImageNamesJSON(path_json, &out_file_paths);
+
+ // We should have only parsed one valid path out of that mess above.
+ EXPECT_EQ(1u, out_file_paths.size());
}
TEST_F(BrowserThemePackTest, InvalidColors) {
@@ -312,6 +335,11 @@ TEST_F(BrowserThemePackTest, InvalidDisplayProperties) {
}
// These three tests should just not cause a segmentation fault.
+TEST_F(BrowserThemePackTest, NullPaths) {
+ std::map<int, FilePath> out_file_paths;
+ ParseImageNamesDictionary(NULL, &out_file_paths);
+}
+
TEST_F(BrowserThemePackTest, NullTints) {
LoadTintDictionary(NULL);
}
diff --git a/chrome/test/data/profiles/complex_theme/Default/Extensions/mblmlcbknbnfebdfjnolmcapmdofhmme/1.1/Cached Theme.pak b/chrome/test/data/profiles/complex_theme/Default/Extensions/mblmlcbknbnfebdfjnolmcapmdofhmme/1.1/Cached Theme.pak
index 0a76cb9..4012706 100644
--- a/chrome/test/data/profiles/complex_theme/Default/Extensions/mblmlcbknbnfebdfjnolmcapmdofhmme/1.1/Cached Theme.pak
+++ b/chrome/test/data/profiles/complex_theme/Default/Extensions/mblmlcbknbnfebdfjnolmcapmdofhmme/1.1/Cached Theme.pak
Binary files differ