This source file includes following definitions.
- SetUpCommandLine
- SetUpInProcessBrowserTestFixture
- GetTestServerURL
- MATCHER
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/cloud_print_private.h"
#include "chrome/test/base/ui_test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::Eq;
using ::testing::Property;
using ::testing::Return;
using ::testing::_;
class ExtensionCloudPrintPrivateApiTest : public ExtensionApiTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(switches::kCloudPrintServiceURL,
"http://www.cloudprintapp.com/files/extensions/api_test/"
"cloud_print_private");
}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
host_resolver()->AddRule("www.cloudprintapp.com", "127.0.0.1");
ASSERT_TRUE(test_server()->Start());
}
protected:
GURL GetTestServerURL(const std::string& path) {
GURL url = test_server()->GetURL(
"files/extensions/api_test/cloud_print_private/" + path);
GURL::Replacements replace_host;
std::string host_str("www.cloudprintapp.com");
replace_host.SetHostStr(host_str);
return url.ReplaceComponents(replace_host);
}
};
#if !defined(OS_CHROMEOS)
using extensions::api::cloud_print_private::UserSettings;
class CloudPrintTestsDelegateMock : public extensions::CloudPrintTestsDelegate {
public:
CloudPrintTestsDelegateMock() {}
MOCK_METHOD4(SetupConnector,
void(const std::string& user_email,
const std::string& robot_email,
const std::string& credentials,
const UserSettings& user_settings));
MOCK_METHOD0(GetHostName, std::string());
MOCK_METHOD0(GetPrinters, std::vector<std::string>());
MOCK_METHOD0(GetClientId, std::string());
private:
DISALLOW_COPY_AND_ASSIGN(CloudPrintTestsDelegateMock);
};
MATCHER(IsExpectedUserSettings, "") {
const UserSettings& settings = arg;
return settings.connect_new_printers &&
settings.printers.size() == 2 &&
settings.printers[0]->name == "printer1" &&
!settings.printers[0]->connect &&
settings.printers[1]->name == "printer2" &&
settings.printers[1]->connect;
}
#if defined(OS_WIN) && !defined(NDEBUG)
#define MAYBE_CloudPrintHosted DISABLED_CloudPrintHosted
#else
#define MAYBE_CloudPrintHosted CloudPrintHosted
#endif
IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest,
MAYBE_CloudPrintHosted) {
CloudPrintTestsDelegateMock cloud_print_mock;
EXPECT_CALL(cloud_print_mock,
SetupConnector("foo@gmail.com",
"foorobot@googleusercontent.com",
"1/23546efa54",
IsExpectedUserSettings()));
EXPECT_CALL(cloud_print_mock, GetHostName())
.WillRepeatedly(Return("TestHostName"));
std::vector<std::string> printers;
printers.push_back("printer1");
printers.push_back("printer2");
EXPECT_CALL(cloud_print_mock, GetPrinters())
.WillRepeatedly(Return(printers));
EXPECT_CALL(cloud_print_mock, GetClientId())
.WillRepeatedly(Return("TestAPIClient"));
GURL page_url = GetTestServerURL(
"enable_chrome_connector/cloud_print_success_tests.html");
ASSERT_TRUE(RunPageTest(page_url.spec()));
}
#endif