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

Unified Diff: chrome/browser/themes/browser_theme_pack_unittest.cc

Issue 2799003002: Unpack theme data from extensions off of UI thread. (Closed)
Patch Set: fix gtk case Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/themes/browser_theme_pack.cc ('k') | chrome/browser/themes/theme_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/themes/browser_theme_pack_unittest.cc
diff --git a/chrome/browser/themes/browser_theme_pack_unittest.cc b/chrome/browser/themes/browser_theme_pack_unittest.cc
index 1180081f35311306a2f6d63683986c4aaac65bf9..22e9d2f905d3f21a714956123c8b34a2a67905bd 100644
--- a/chrome/browser/themes/browser_theme_pack_unittest.cc
+++ b/chrome/browser/themes/browser_theme_pack_unittest.cc
@@ -10,6 +10,7 @@
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_reader.h"
#include "base/path_service.h"
+#include "base/synchronization/waitable_event.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/themes/theme_properties.h"
@@ -34,14 +35,16 @@ typedef std::map<int, TestScaleFactorToFileMap> TestFilePathMap;
class BrowserThemePackTest : public ::testing::Test {
public:
- BrowserThemePackTest() {
+ BrowserThemePackTest()
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD),
+ theme_pack_(new BrowserThemePack()) {
std::vector<ui::ScaleFactor> scale_factors;
scale_factors.push_back(ui::SCALE_FACTOR_100P);
scale_factors.push_back(ui::SCALE_FACTOR_200P);
scoped_set_supported_scale_factors_.reset(
- new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
- theme_pack_ = new BrowserThemePack();
+ new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
}
+ ~BrowserThemePackTest() override {}
// Transformation for link underline colors.
SkColor BuildThirdOpacity(SkColor color_link) {
@@ -142,33 +145,22 @@ class BrowserThemePackTest : public ::testing::Test {
}
bool LoadRawBitmapsTo(const TestFilePathMap& out_file_paths) {
- return theme_pack_->LoadRawBitmapsTo(out_file_paths,
- &theme_pack_->images_on_ui_thread_);
+ return theme_pack_->LoadRawBitmapsTo(out_file_paths, &theme_pack_->images_);
}
// This function returns void in order to be able use ASSERT_...
// The BrowserThemePack is returned in |pack|.
void BuildFromUnpackedExtension(const base::FilePath& extension_path,
- scoped_refptr<BrowserThemePack>& pack) {
- base::FilePath manifest_path =
- extension_path.AppendASCII("manifest.json");
- std::string error;
- JSONFileValueDeserializer deserializer(manifest_path);
- std::unique_ptr<base::DictionaryValue> valid_value =
- base::DictionaryValue::From(deserializer.Deserialize(NULL, &error));
- EXPECT_EQ("", error);
- ASSERT_TRUE(valid_value.get());
- scoped_refptr<Extension> extension(
- Extension::Create(
- extension_path,
- extensions::Manifest::INVALID_LOCATION,
- *valid_value,
- Extension::REQUIRE_KEY,
- &error));
- ASSERT_TRUE(extension.get());
- ASSERT_EQ("", error);
- pack = BrowserThemePack::BuildFromExtension(extension.get());
- ASSERT_TRUE(pack.get());
+ scoped_refptr<BrowserThemePack>* pack) {
+ io_waiter_.reset(new base::WaitableEvent(
+ base::WaitableEvent::ResetPolicy::AUTOMATIC,
+ base::WaitableEvent::InitialState::NOT_SIGNALED));
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&BrowserThemePackTest::DoBuildFromUnpackedExtension,
+ base::Unretained(this), extension_path, pack));
+ io_waiter_->Wait();
+ ASSERT_TRUE((*pack)->is_valid());
}
base::FilePath GetStarGazingPath() {
@@ -347,12 +339,33 @@ class BrowserThemePackTest : public ::testing::Test {
}
}
- content::TestBrowserThreadBundle test_browser_thread_bundle_;
-
+ protected:
typedef std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors>
ScopedSetSupportedScaleFactors;
ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_;
+
+ void DoBuildFromUnpackedExtension(const base::FilePath& extension_path,
+ scoped_refptr<BrowserThemePack>* pack) {
+ base::FilePath manifest_path = extension_path.AppendASCII("manifest.json");
+ std::string error;
+ JSONFileValueDeserializer deserializer(manifest_path);
+ std::unique_ptr<base::DictionaryValue> valid_value =
+ base::DictionaryValue::From(deserializer.Deserialize(NULL, &error));
+ EXPECT_EQ("", error);
+ ASSERT_TRUE(valid_value.get());
+ scoped_refptr<Extension> extension(Extension::Create(
+ extension_path, extensions::Manifest::INVALID_LOCATION, *valid_value,
+ Extension::REQUIRE_KEY, &error));
+ ASSERT_TRUE(extension.get());
+ ASSERT_EQ("", error);
+ *pack = new BrowserThemePack;
+ BrowserThemePack::BuildFromExtension(extension.get(), *pack);
+ io_waiter_->Signal();
+ }
+
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_refptr<BrowserThemePack> theme_pack_;
+ std::unique_ptr<base::WaitableEvent> io_waiter_;
};
// 'ntp_section' used to correspond to ThemeProperties::COLOR_NTP_SECTION,
@@ -569,7 +582,7 @@ TEST_F(BrowserThemePackTest, CanBuildAndReadPack) {
{
base::FilePath star_gazing_path = GetStarGazingPath();
scoped_refptr<BrowserThemePack> pack;
- BuildFromUnpackedExtension(star_gazing_path, pack);
+ BuildFromUnpackedExtension(star_gazing_path, &pack);
ASSERT_TRUE(pack->WriteToDisk(file));
VerifyStarGazing(pack.get());
}
@@ -593,7 +606,7 @@ TEST_F(BrowserThemePackTest, HiDpiThemeTest) {
{
base::FilePath hidpi_path = GetHiDpiThemePath();
scoped_refptr<BrowserThemePack> pack;
- BuildFromUnpackedExtension(hidpi_path, pack);
+ BuildFromUnpackedExtension(hidpi_path, &pack);
ASSERT_TRUE(pack->WriteToDisk(file));
VerifyHiDpiTheme(pack.get());
}
« no previous file with comments | « chrome/browser/themes/browser_theme_pack.cc ('k') | chrome/browser/themes/theme_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698