This source file includes following definitions.
- TestCheckRequestorPermitted
- TestInstallerCallback
- SetUp
- TearDown
- TestSingleVerifiedSite
- TestMultipleVerifiedSites
- TEST_F
#include <vector>
#include "chrome/browser/extensions/webstore_inline_installer.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/web_contents.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace extensions {
namespace {
class TestWebstoreInlineInstaller : public WebstoreInlineInstaller {
public:
explicit TestWebstoreInlineInstaller(content::WebContents* contents,
const std::string& requestor_url);
bool TestCheckRequestorPermitted(const base::DictionaryValue& webstore_data) {
std::string error;
return CheckRequestorPermitted(webstore_data, &error);
}
protected:
virtual ~TestWebstoreInlineInstaller();
};
void TestInstallerCallback(bool success, const std::string& error) {}
TestWebstoreInlineInstaller::TestWebstoreInlineInstaller(
content::WebContents* contents,
const std::string& requestor_url)
: WebstoreInlineInstaller(contents,
"",
GURL(requestor_url),
base::Bind(&TestInstallerCallback)) {
}
TestWebstoreInlineInstaller::~TestWebstoreInlineInstaller() {}
class WebstoreInlineInstallerTest : public ChromeRenderViewHostTestHarness {
public:
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
bool TestSingleVerifiedSite(const std::string& requestor_url,
const std::string& verified_site);
bool TestMultipleVerifiedSites(
const std::string& requestor_url,
const std::vector<std::string>& verified_sites);
protected:
scoped_ptr<content::WebContents> web_contents_;
};
void WebstoreInlineInstallerTest::SetUp() {
ChromeRenderViewHostTestHarness::SetUp();
web_contents_.reset(CreateTestWebContents());
}
void WebstoreInlineInstallerTest::TearDown() {
web_contents_.reset(NULL);
ChromeRenderViewHostTestHarness::TearDown();
}
bool WebstoreInlineInstallerTest::TestSingleVerifiedSite(
const std::string& requestor_url,
const std::string& verified_site) {
base::DictionaryValue webstore_data;
webstore_data.SetString("verified_site", verified_site);
scoped_refptr<TestWebstoreInlineInstaller> installer =
new TestWebstoreInlineInstaller(web_contents_.get(), requestor_url);
return installer->TestCheckRequestorPermitted(webstore_data);
}
bool WebstoreInlineInstallerTest::TestMultipleVerifiedSites(
const std::string& requestor_url,
const std::vector<std::string>& verified_sites) {
base::ListValue* sites = new base::ListValue();
for (std::vector<std::string>::const_iterator it = verified_sites.begin();
it != verified_sites.end(); ++it) {
sites->Append(new base::StringValue(*it));
}
base::DictionaryValue webstore_data;
webstore_data.Set("verified_sites", sites);
scoped_refptr<TestWebstoreInlineInstaller> installer =
new TestWebstoreInlineInstaller(web_contents_.get(), requestor_url);
return installer->TestCheckRequestorPermitted(webstore_data);
}
}
TEST_F(WebstoreInlineInstallerTest, DomainVerification) {
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com", "example.com"));
EXPECT_TRUE(TestSingleVerifiedSite("https://example.com", "example.com"));
EXPECT_FALSE(TestSingleVerifiedSite("file:///example.com", "example.com"));
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/", "example.com"));
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/page.html",
"example.com"));
EXPECT_TRUE(TestSingleVerifiedSite("http://sub.example.com/page.html",
"example.com"));
EXPECT_FALSE(TestSingleVerifiedSite("http://example.com/",
"sub.example.com"));
EXPECT_FALSE(TestSingleVerifiedSite("http://www.example.com/",
"sub.example.com"));
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com:123/",
"example.com:123"));
EXPECT_FALSE(TestSingleVerifiedSite("http://example.com:456/",
"example.com:123"));
EXPECT_FALSE(TestSingleVerifiedSite("http://example.com/",
"example.com:123"));
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com:123/", "example.com"));
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/path",
"example.com/path"));
EXPECT_FALSE(TestSingleVerifiedSite("http://example.com/foo",
"example.com/path"));
EXPECT_FALSE(TestSingleVerifiedSite("http://example.com",
"example.com/path"));
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/path/",
"example.com/path"));
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/path/page.html",
"example.com/path"));
EXPECT_TRUE(TestSingleVerifiedSite(
"http://example.com:123/path/page.html", "example.com:123/path"));
EXPECT_TRUE(TestSingleVerifiedSite("http://example.com",
"http://example.com"));
EXPECT_TRUE(TestSingleVerifiedSite("https://example.com",
"https://example.com"));
EXPECT_FALSE(TestSingleVerifiedSite("https://example.com",
"http://example.com"));
EXPECT_FALSE(TestSingleVerifiedSite("http://example.com",
"https://example.com"));
EXPECT_FALSE(TestSingleVerifiedSite("file://example.com",
"file://example.com"));
std::vector<std::string> verified_sites;
verified_sites.push_back("foo.example.com");
verified_sites.push_back("bar.example.com:123");
verified_sites.push_back("example.com/unicorns");
EXPECT_TRUE(TestMultipleVerifiedSites("http://foo.example.com",
verified_sites));
EXPECT_TRUE(TestMultipleVerifiedSites("http://bar.example.com:123",
verified_sites));
EXPECT_TRUE(TestMultipleVerifiedSites(
"http://cooking.example.com/unicorns/bacon.html", verified_sites));
EXPECT_FALSE(TestMultipleVerifiedSites("http://example.com",
verified_sites));
EXPECT_FALSE(TestMultipleVerifiedSites("file://foo.example.com",
verified_sites));
EXPECT_FALSE(TestMultipleVerifiedSites("http://baz.example.com",
verified_sites));
EXPECT_FALSE(TestMultipleVerifiedSites("http://bar.example.com:456",
verified_sites));
}
}