This source file includes following definitions.
- NavigateAndGetInfo
- ACTION
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- foo_provider
- SetUpOnMainThread
- CleanUpOnMainThread
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/session_storage_namespace.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
namespace {
struct ContentInfo {
ContentInfo(int pid, content::StoragePartition* storage_partition) {
this->pid = pid;
this->storage_partition = storage_partition;
}
int pid;
content::StoragePartition* storage_partition;
};
ContentInfo NavigateAndGetInfo(
Browser* browser,
const GURL& url,
WindowOpenDisposition disposition) {
ui_test_utils::NavigateToURLWithDisposition(
browser, url, disposition,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
content::WebContents* contents =
browser->tab_strip_model()->GetActiveWebContents();
content::RenderProcessHost* process = contents->GetRenderProcessHost();
return ContentInfo(process->GetID(), process->GetStoragePartition());
}
ACTION(ReturnNewWebUI) {
return new content::WebUIController(arg0);
}
class FooWebUIProvider
: public TestChromeWebUIControllerFactory::WebUIProvider {
public:
MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui,
const GURL& url));
};
const char kFooWebUIURL[] = "chrome://foo/";
}
class InlineLoginUIBrowserTest : public InProcessBrowserTest {
public:
InlineLoginUIBrowserTest() {}
};
IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, DifferentStorageId) {
GURL test_url = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(FILE_PATH_LITERAL("title1.html")));
ContentInfo info1 =
NavigateAndGetInfo(browser(), test_url, CURRENT_TAB);
ContentInfo info2 =
NavigateAndGetInfo(browser(),
signin::GetPromoURL(signin::SOURCE_START_PAGE, false),
CURRENT_TAB);
NavigateAndGetInfo(browser(), test_url, CURRENT_TAB);
ContentInfo info3 =
NavigateAndGetInfo(browser(),
signin::GetPromoURL( signin::SOURCE_START_PAGE, false),
NEW_FOREGROUND_TAB);
ASSERT_EQ(info2.storage_partition, info3.storage_partition);
ASSERT_NE(info1.storage_partition, info2.storage_partition);
}
IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, OneProcessLimit) {
GURL test_url_1 = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(FILE_PATH_LITERAL("title1.html")));
GURL test_url_2 = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(FILE_PATH_LITERAL("data:text/html,Hello world!")));
content::RenderProcessHost::SetMaxRendererProcessCount(1);
ContentInfo info1 =
NavigateAndGetInfo(browser(), test_url_1, CURRENT_TAB);
ContentInfo info2 =
NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB);
ContentInfo info3 =
NavigateAndGetInfo(browser(),
signin::GetPromoURL( signin::SOURCE_START_PAGE, false),
CURRENT_TAB);
ASSERT_EQ(info1.pid, info2.pid);
ASSERT_NE(info1.pid, info3.pid);
}
class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest {
public:
FooWebUIProvider& foo_provider() { return foo_provider_; }
private:
virtual void SetUpOnMainThread() OVERRIDE {
content::WebUIControllerFactory::UnregisterFactoryForTesting(
ChromeWebUIControllerFactory::GetInstance());
test_factory_.reset(new TestChromeWebUIControllerFactory);
content::WebUIControllerFactory::RegisterFactory(test_factory_.get());
test_factory_->AddFactoryOverride(
GURL(kFooWebUIURL).host(), &foo_provider_);
}
virtual void CleanUpOnMainThread() OVERRIDE {
test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host());
content::WebUIControllerFactory::UnregisterFactoryForTesting(
test_factory_.get());
test_factory_.reset();
}
FooWebUIProvider foo_provider_;
scoped_ptr<TestChromeWebUIControllerFactory> test_factory_;
};
IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) {
const GURL kUrl(kFooWebUIURL);
EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl)))
.WillOnce(ReturnNewWebUI());
ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL));
}
IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) {
GURL url = signin::GetPromoURL(signin::SOURCE_START_PAGE, false).
Resolve("?source=0&frameUrl=chrome://foo");
EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0);
ui_test_utils::NavigateToURL(browser(), url);
}