Commit 6ef22ff8 authored by Himanshu Jaju's avatar Himanshu Jaju Committed by Commit Bot

Integration tests for click to call.

- No device with telephony capability
- Device available but sync turned off

Bug: 982229
Change-Id: I7eb6fe5226cbac9295faf47c8c20d487677a5273
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1726053
Commit-Queue: Himanshu Jaju <himanshujaju@chromium.org>
Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683242}
parent acc15e01
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "chrome/browser/sync/test/integration/sync_test.h" #include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "components/gcm_driver/fake_gcm_profile_service.h" #include "components/gcm_driver/fake_gcm_profile_service.h"
#include "components/sync/driver/sync_driver_switches.h" #include "components/sync/driver/profile_sync_service.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace { namespace {
...@@ -52,13 +52,15 @@ class ClickToCallBrowserTest : public SyncTest { ...@@ -52,13 +52,15 @@ class ClickToCallBrowserTest : public SyncTest {
std::unique_ptr<content::WebContents> web_contents_ptr = std::unique_ptr<content::WebContents> web_contents_ptr =
content::WebContents::Create( content::WebContents::Create(
content::WebContents::CreateParams(GetProfile(0))); content::WebContents::CreateParams(GetProfile(0)));
web_contents = web_contents_ptr.get(); web_contents_ = web_contents_ptr.get();
Browser* browser = AddBrowser(0); Browser* browser = AddBrowser(0);
browser->tab_strip_model()->AppendWebContents(std::move(web_contents_ptr), browser->tab_strip_model()->AppendWebContents(std::move(web_contents_ptr),
true); true);
}
content::WebContents* GetWebContents() { return web_contents; } gcm_service_ = static_cast<gcm::FakeGCMProfileService*>(
gcm::GCMProfileServiceFactory::GetForProfile(GetProfile(0)));
gcm_service_->set_collect(true);
}
void SetUpDevices(int count) { void SetUpDevices(int count) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
...@@ -78,7 +80,6 @@ class ClickToCallBrowserTest : public SyncTest { ...@@ -78,7 +80,6 @@ class ClickToCallBrowserTest : public SyncTest {
} }
std::unique_ptr<TestRenderViewContextMenu> InitRightClickMenu( std::unique_ptr<TestRenderViewContextMenu> InitRightClickMenu(
content::WebContents* web_contents,
const GURL& url, const GURL& url,
const base::string16& link_text) { const base::string16& link_text) {
content::ContextMenuParams params; content::ContextMenuParams params;
...@@ -87,7 +88,7 @@ class ClickToCallBrowserTest : public SyncTest { ...@@ -87,7 +88,7 @@ class ClickToCallBrowserTest : public SyncTest {
params.link_url = url; params.link_url = url;
params.src_url = url; params.src_url = url;
params.link_text = link_text; params.link_text = link_text;
params.page_url = web_contents->GetVisibleURL(); params.page_url = web_contents_->GetVisibleURL();
params.source_type = ui::MenuSourceType::MENU_SOURCE_MOUSE; params.source_type = ui::MenuSourceType::MENU_SOURCE_MOUSE;
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
params.writing_direction_default = 0; params.writing_direction_default = 0;
...@@ -95,7 +96,7 @@ class ClickToCallBrowserTest : public SyncTest { ...@@ -95,7 +96,7 @@ class ClickToCallBrowserTest : public SyncTest {
params.writing_direction_right_to_left = 0; params.writing_direction_right_to_left = 0;
#endif #endif
auto menu = std::make_unique<TestRenderViewContextMenu>( auto menu = std::make_unique<TestRenderViewContextMenu>(
web_contents->GetMainFrame(), params); web_contents_->GetMainFrame(), params);
menu->Init(); menu->Init();
return menu; return menu;
} }
...@@ -109,33 +110,30 @@ class ClickToCallBrowserTest : public SyncTest { ...@@ -109,33 +110,30 @@ class ClickToCallBrowserTest : public SyncTest {
*fcm_token = it->second.fcm_token; *fcm_token = it->second.fcm_token;
} }
gcm::FakeGCMProfileService* GetGCMService() const { return gcm_service_; }
private: private:
gcm::GCMProfileServiceFactory::ScopedTestingFactoryInstaller gcm::GCMProfileServiceFactory::ScopedTestingFactoryInstaller
scoped_testing_factory_installer_; scoped_testing_factory_installer_;
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
content::WebContents* web_contents; gcm::FakeGCMProfileService* gcm_service_;
std::vector<std::string> device_fcm_tokens_; content::WebContents* web_contents_;
DISALLOW_COPY_AND_ASSIGN(ClickToCallBrowserTest); DISALLOW_COPY_AND_ASSIGN(ClickToCallBrowserTest);
}; };
// TODO(himanshujaju): Add UI checks. Modularize common functions. // TODO(himanshujaju): Add UI checks. Modularize common functions.
IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest,
ContextMenu_SingleDeviceAvailable) { ContextMenu_SingleDeviceAvailable) {
SetUpDevices(1); SetUpDevices(/*count=*/1);
AwaitQuiescence(); AwaitQuiescence();
gcm::FakeGCMProfileService* gcm_service =
static_cast<gcm::FakeGCMProfileService*>(
gcm::GCMProfileServiceFactory::GetForProfile(GetProfile(0)));
gcm_service->set_collect(true);
SharingService* sharing_service = SharingService* sharing_service =
SharingServiceFactory::GetForBrowserContext(GetProfile(0)); SharingServiceFactory::GetForBrowserContext(GetProfile(0));
auto devices = sharing_service->GetDeviceCandidates( auto devices = sharing_service->GetDeviceCandidates(
static_cast<int>(SharingDeviceCapability::kTelephony)); static_cast<int>(SharingDeviceCapability::kTelephony));
std::unique_ptr<TestRenderViewContextMenu> menu = InitRightClickMenu( std::unique_ptr<TestRenderViewContextMenu> menu =
GetWebContents(), GURL(kTelUrl), base::ASCIIToUTF16("Google")); InitRightClickMenu(GURL(kTelUrl), base::ASCIIToUTF16("Google"));
// Check click to call items in context menu // Check click to call items in context menu
ASSERT_TRUE(menu->IsItemPresent( ASSERT_TRUE(menu->IsItemPresent(
...@@ -149,10 +147,36 @@ IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, ...@@ -149,10 +147,36 @@ IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest,
// Check SharingMessage and Receiver id // Check SharingMessage and Receiver id
std::string fcm_token; std::string fcm_token;
GetDeviceFCMToken(sharing_service, devices[0].guid(), &fcm_token); GetDeviceFCMToken(sharing_service, devices[0].guid(), &fcm_token);
EXPECT_EQ(fcm_token, gcm_service->last_receiver_id()); EXPECT_EQ(fcm_token, GetGCMService()->last_receiver_id());
chrome_browser_sharing::SharingMessage sharing_message; chrome_browser_sharing::SharingMessage sharing_message;
sharing_message.ParseFromString(gcm_service->last_web_push_message().payload); sharing_message.ParseFromString(
GetGCMService()->last_web_push_message().payload);
ASSERT_TRUE(sharing_message.has_click_to_call_message()); ASSERT_TRUE(sharing_message.has_click_to_call_message());
EXPECT_EQ(GURL(kTelUrl).GetContent(), EXPECT_EQ(GURL(kTelUrl).GetContent(),
sharing_message.click_to_call_message().phone_number()); sharing_message.click_to_call_message().phone_number());
} }
IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, ContextMenu_NoDevicesAvailable) {
AwaitQuiescence();
std::unique_ptr<TestRenderViewContextMenu> menu =
InitRightClickMenu(GURL(kTelUrl), base::ASCIIToUTF16("Google"));
EXPECT_FALSE(menu->IsItemPresent(
IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE));
EXPECT_FALSE(menu->IsItemPresent(
IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_MULTIPLE_DEVICES));
}
IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest,
ContextMenu_DevicesAvailable_SyncTurnedOff) {
SetUpDevices(/*count=*/1);
AwaitQuiescence();
GetSyncService(0)->GetUserSettings()->SetSyncRequested(false);
std::unique_ptr<TestRenderViewContextMenu> menu =
InitRightClickMenu(GURL(kTelUrl), base::ASCIIToUTF16("Google"));
EXPECT_FALSE(menu->IsItemPresent(
IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE));
EXPECT_FALSE(menu->IsItemPresent(
IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_MULTIPLE_DEVICES));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment