This source file includes following definitions.
- QuitMessageLoop
- WaitForStateStore
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/extensions/state_store.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "third_party/skia/include/core/SkColor.h"
namespace extensions {
namespace {
const char kBrowserActionStorageKey[] = "browser_action";
const char kExtensionName[] = "Default Persistence Test Extension";
void QuitMessageLoop(content::MessageLoopRunner* runner,
scoped_ptr<base::Value> value) {
runner->Quit();
}
void WaitForStateStore(Profile* profile, const std::string& extension_id) {
scoped_refptr<content::MessageLoopRunner> runner =
new content::MessageLoopRunner;
ExtensionSystem::Get(profile)->state_store()->GetExtensionValue(
extension_id,
kBrowserActionStorageKey,
base::Bind(&QuitMessageLoop, runner));
runner->Run();
}
}
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
PRE_BrowserActionDefaultPersistence) {
ExtensionTestMessageListener listener("Background Color Set",
false );
const Extension* extension =
LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("default_persistence"));
ASSERT_TRUE(extension);
ASSERT_EQ(kExtensionName, extension->name());
WaitForStateStore(profile(), extension->id());
ASSERT_TRUE(listener.WaitUntilSatisfied());
ExtensionAction* extension_action =
ExtensionActionManager::Get(profile())->GetBrowserAction(*extension);
ASSERT_TRUE(extension_action);
EXPECT_EQ(SK_ColorBLUE, extension_action->GetBadgeBackgroundColor(0));
}
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, BrowserActionDefaultPersistence) {
const Extension* extension = NULL;
const ExtensionSet& extension_set =
ExtensionRegistry::Get(profile())->enabled_extensions();
for (ExtensionSet::const_iterator iter = extension_set.begin();
iter != extension_set.end();
++iter) {
if ((*iter)->name() == kExtensionName) {
extension = *iter;
break;
}
}
ASSERT_TRUE(extension) << "Could not find extension in registry.";
ExtensionAction* extension_action =
ExtensionActionManager::Get(profile())->GetBrowserAction(*extension);
ASSERT_TRUE(extension_action);
if (extension_action->GetBadgeText(0) != "Hello") {
ExtensionTestMessageListener listener("Badge Text Set",
false );
ASSERT_TRUE(listener.WaitUntilSatisfied());
}
if (ExtensionSystem::Get(profile())->state_store()->IsInitialized())
LOG(WARNING) << "State store already initialized; test guaranteed to pass.";
WaitForStateStore(profile(), extension->id());
EXPECT_EQ(SK_ColorBLUE, extension_action->GetBadgeBackgroundColor(0));
}
}