This source file includes following definitions.
- CreateExtension
- CreateExtensionWithBackgroundPage
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "extensions/browser/runtime_data.h"
#include <string>
#include "base/memory/ref_counted.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace {
scoped_refptr<Extension> CreateExtension() {
return ExtensionBuilder()
.SetManifest(
DictionaryBuilder().Set("name", "test").Set("version", "0.1"))
.SetID("id1")
.Build();
}
scoped_refptr<Extension> CreateExtensionWithBackgroundPage() {
return ExtensionBuilder()
.SetManifest(
DictionaryBuilder()
.Set("name", "test")
.Set("version", "0.1")
.Set("background", DictionaryBuilder().Set("page", "bg.html")))
.SetID("id2")
.Build();
}
class RuntimeDataTest : public testing::Test {
public:
RuntimeDataTest() : runtime_data_(®istry_) {}
virtual ~RuntimeDataTest() {}
protected:
ExtensionRegistry registry_;
RuntimeData runtime_data_;
private:
DISALLOW_COPY_AND_ASSIGN(RuntimeDataTest);
};
TEST_F(RuntimeDataTest, IsBackgroundPageReady) {
scoped_refptr<Extension> no_background = CreateExtension();
EXPECT_TRUE(runtime_data_.IsBackgroundPageReady(no_background));
scoped_refptr<Extension> with_background =
CreateExtensionWithBackgroundPage();
EXPECT_FALSE(runtime_data_.IsBackgroundPageReady(with_background));
runtime_data_.SetBackgroundPageReady(with_background, true);
EXPECT_TRUE(runtime_data_.IsBackgroundPageReady(with_background));
runtime_data_.SetBackgroundPageReady(with_background, false);
EXPECT_FALSE(runtime_data_.IsBackgroundPageReady(with_background));
}
TEST_F(RuntimeDataTest, IsBeingUpgraded) {
scoped_refptr<Extension> extension = CreateExtension();
EXPECT_FALSE(runtime_data_.IsBeingUpgraded(extension));
runtime_data_.SetBeingUpgraded(extension, true);
EXPECT_TRUE(runtime_data_.IsBeingUpgraded(extension));
runtime_data_.SetBeingUpgraded(extension, false);
EXPECT_FALSE(runtime_data_.IsBeingUpgraded(extension));
}
TEST_F(RuntimeDataTest, HasUsedWebRequest) {
scoped_refptr<Extension> extension = CreateExtension();
EXPECT_FALSE(runtime_data_.HasUsedWebRequest(extension));
runtime_data_.SetHasUsedWebRequest(extension, true);
EXPECT_TRUE(runtime_data_.HasUsedWebRequest(extension));
runtime_data_.SetHasUsedWebRequest(extension, false);
EXPECT_FALSE(runtime_data_.HasUsedWebRequest(extension));
}
TEST_F(RuntimeDataTest, OnExtensionUnloaded) {
scoped_refptr<Extension> extension = CreateExtensionWithBackgroundPage();
runtime_data_.SetBackgroundPageReady(extension, true);
ASSERT_TRUE(runtime_data_.HasExtensionForTesting(extension));
runtime_data_.OnExtensionUnloaded(extension);
EXPECT_FALSE(runtime_data_.HasExtensionForTesting(extension));
}
}
}