Commit 2466dcec authored by Jian Li's avatar Jian Li Committed by Commit Bot

Revert "Integration tests for click to call"

This reverts commit 107a4e3e.

Reason for revert: <INSERT REASONING HERE>

==20541==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x557884d1cbb9 in ClickToCallIconView::Update() ./../../chrome/browser/ui/views/sharing/click_to_call/click_to_call_icon_view.cc:80:7

https://ci.chromium.org/p/chromium/builders/ci/Linux%20MSan%20Tests/18323

The real issue indeed lies in click_to_call_icon_view.h

Original change's description:
> Integration tests for click to call
> 
> Bug: 982229
> Change-Id: I3d0f19b55dc6dc07c6ad427d670aaa2db0a9af2d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1718410
> Commit-Queue: Himanshu Jaju <himanshujaju@chromium.org>
> Reviewed-by: Peter Beverloo <peter@chromium.org>
> Reviewed-by: Richard Knoll <knollr@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#682242}

TBR=peter@chromium.org,knollr@chromium.org,himanshujaju@chromium.org

Change-Id: Ic56b5b5bd151f42992ba4bc8d9e13e73dd135983
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 982229
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1727231Reviewed-by: default avatarJian Li <jianli@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682405}
parent 98447da8
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <string>
#include "base/bind.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/sharing/click_to_call/feature.h"
#include "chrome/browser/sharing/features.h"
#include "chrome/browser/sharing/sharing_device_info.h"
#include "chrome/browser/sharing/sharing_device_registration_result.h"
#include "chrome/browser/sharing/sharing_service.h"
#include "chrome/browser/sharing/sharing_service_factory.h"
#include "chrome/browser/sharing/sharing_sync_preference.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/browser.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "url/gurl.h"
namespace {
const char kTelUrl[] = "tel:+9876543210";
} // namespace
class ClickToCallBrowserTest : public SyncTest {
public:
ClickToCallBrowserTest()
: SyncTest(TWO_CLIENT),
scoped_testing_factory_installer_(
base::BindRepeating(&gcm::FakeGCMProfileService::Build)) {}
~ClickToCallBrowserTest() override {}
void SetUpOnMainThread() override {
SyncTest::SetUpOnMainThread();
scoped_feature_list_.InitWithFeatures(
{kClickToCallUI, kSharingDeviceRegistration}, {});
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
std::unique_ptr<content::WebContents> web_contents_ptr =
content::WebContents::Create(
content::WebContents::CreateParams(GetProfile(0)));
web_contents = web_contents_ptr.get();
Browser* browser = AddBrowser(0);
browser->tab_strip_model()->AppendWebContents(std::move(web_contents_ptr),
true);
}
content::WebContents* GetWebContents() { return web_contents; }
void SetUpDevices(int count) {
for (int i = 0; i < count; i++) {
SharingService* service =
SharingServiceFactory::GetForBrowserContext(GetProfile(i));
base::RunLoop run_loop;
service->RegisterDeviceInTesting(
std::string("TEST"),
static_cast<int>(SharingDeviceCapability::kTelephony),
base::BindLambdaForTesting([&](SharingDeviceRegistrationResult r) {
ASSERT_EQ(SharingDeviceRegistrationResult::kSuccess, r);
run_loop.Quit();
}));
run_loop.Run();
}
}
std::unique_ptr<TestRenderViewContextMenu> InitRightClickMenu(
content::WebContents* web_contents,
const GURL& url,
const base::string16& link_text) {
content::ContextMenuParams params;
params.media_type = blink::WebContextMenuData::MediaType::kMediaTypeNone;
params.unfiltered_link_url = url;
params.link_url = url;
params.src_url = url;
params.link_text = link_text;
params.page_url = web_contents->GetVisibleURL();
params.source_type = ui::MenuSourceType::MENU_SOURCE_MOUSE;
#if defined(OS_MACOSX)
params.writing_direction_default = 0;
params.writing_direction_left_to_right = 0;
params.writing_direction_right_to_left = 0;
#endif
auto menu = std::make_unique<TestRenderViewContextMenu>(
web_contents->GetMainFrame(), params);
menu->Init();
return menu;
}
void GetDeviceFCMToken(SharingService* sharing_service,
const std::string& guid,
std::string* fcm_token) const {
auto devices = sharing_service->GetSyncPreferences()->GetSyncedDevices();
auto it = devices.find(guid);
ASSERT_NE(devices.end(), it);
*fcm_token = it->second.fcm_token;
}
private:
gcm::GCMProfileServiceFactory::ScopedTestingFactoryInstaller
scoped_testing_factory_installer_;
base::test::ScopedFeatureList scoped_feature_list_;
content::WebContents* web_contents;
std::vector<std::string> device_fcm_tokens_;
DISALLOW_COPY_AND_ASSIGN(ClickToCallBrowserTest);
};
// TODO(himanshujaju): Add UI checks. Modularize common functions.
IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest,
ContextMenu_SingleDeviceAvailable) {
SetUpDevices(1);
AwaitQuiescence();
gcm::FakeGCMProfileService* gcm_service =
static_cast<gcm::FakeGCMProfileService*>(
gcm::GCMProfileServiceFactory::GetForProfile(GetProfile(0)));
gcm_service->set_collect(true);
SharingService* sharing_service =
SharingServiceFactory::GetForBrowserContext(GetProfile(0));
auto devices = sharing_service->GetDeviceCandidates(
static_cast<int>(SharingDeviceCapability::kTelephony));
std::unique_ptr<TestRenderViewContextMenu> menu = InitRightClickMenu(
GetWebContents(), GURL(kTelUrl), base::ASCIIToUTF16("Google"));
// Check click to call items in context menu
ASSERT_TRUE(menu->IsItemPresent(
IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE));
EXPECT_FALSE(menu->IsItemPresent(
IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_MULTIPLE_DEVICES));
menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE,
0);
// Check SharingMessage and Receiver id
std::string fcm_token;
GetDeviceFCMToken(sharing_service, devices[0].guid(), &fcm_token);
EXPECT_EQ(fcm_token, gcm_service->last_receiver_id());
chrome_browser_sharing::SharingMessage sharing_message;
sharing_message.ParseFromString(gcm_service->last_web_push_message().payload);
ASSERT_TRUE(sharing_message.has_click_to_call_message());
EXPECT_EQ(GURL(kTelUrl).GetContent(),
sharing_message.click_to_call_message().phone_number());
}
......@@ -188,10 +188,6 @@ base::Optional<std::string> SharingDeviceRegistration::GetAuthorizationEntity()
}
int SharingDeviceRegistration::GetDeviceCapabilities() const {
// Used in tests
if (device_capabilities_testing_value_)
return device_capabilities_testing_value_.value();
int device_capabilities = static_cast<int>(SharingDeviceCapability::kNone);
if (IsTelephonySupported()) {
device_capabilities |=
......@@ -210,8 +206,3 @@ bool SharingDeviceRegistration::IsTelephonySupported() const {
return false;
}
void SharingDeviceRegistration::SetDeviceCapabilityForTesting(
int device_capabilities) {
device_capabilities_testing_value_ = device_capabilities;
}
......@@ -47,9 +47,6 @@ class SharingDeviceRegistration {
// Un-registers device with sharing sync preferences.
virtual void UnregisterDevice(RegistrationCallback callback);
// For testing
void SetDeviceCapabilityForTesting(int device_capabilities);
private:
FRIEND_TEST_ALL_PREFIXES(SharingDeviceRegistrationTest,
RegisterDeviceTest_Success);
......@@ -94,7 +91,6 @@ class SharingDeviceRegistration {
instance_id::InstanceIDDriver* instance_id_driver_;
VapidKeyManager* vapid_key_manager_;
syncer::LocalDeviceInfoProvider* local_device_info_provider_;
base::Optional<int> device_capabilities_testing_value_;
base::WeakPtrFactory<SharingDeviceRegistration> weak_ptr_factory_{this};
......
......@@ -127,6 +127,8 @@ std::vector<SharingDeviceInfo> SharingService::GetDeviceCandidates(
std::unordered_set<std::string> device_names;
std::vector<SharingDeviceInfo> device_candidates;
const syncer::DeviceInfo* local_device_info =
local_device_info_provider_->GetLocalDeviceInfo();
for (const auto& device : all_devices) {
// If the current device is considered expired for our purposes, stop here
// since the next devices in the vector are at least as expired than this
......@@ -134,7 +136,8 @@ std::vector<SharingDeviceInfo> SharingService::GetDeviceCandidates(
if (device->last_updated_timestamp() < min_updated_time)
break;
if (GetDeviceName() == device->client_name()) {
if (local_device_info &&
(local_device_info->client_name() == device->client_name())) {
continue;
}
......@@ -265,15 +268,6 @@ void SharingService::RegisterDevice() {
&SharingService::OnDeviceRegistered, weak_ptr_factory_.GetWeakPtr()));
}
void SharingService::RegisterDeviceInTesting(
std::string device_name,
int capabilities,
SharingDeviceRegistration::RegistrationCallback callback) {
local_device_name_for_tests_ = std::move(device_name);
sharing_device_registration_->SetDeviceCapabilityForTesting(capabilities);
sharing_device_registration_->RegisterDevice(std::move(callback));
}
void SharingService::UnregisterDevice() {
sharing_device_registration_->UnregisterDevice(base::BindOnce(
&SharingService::OnDeviceUnregistered, weak_ptr_factory_.GetWeakPtr()));
......@@ -364,10 +358,6 @@ bool SharingService::IsSyncEnabled() const {
sync_service_->GetActiveDataTypes().Has(syncer::PREFERENCES);
}
SharingSyncPreference* SharingService::GetSyncPreferences() const {
return sync_prefs_.get();
}
bool SharingService::IsSyncDisabled() const {
return sync_service_ &&
(sync_service_->GetTransportState() ==
......@@ -376,15 +366,3 @@ bool SharingService::IsSyncDisabled() const {
syncer::SyncService::TransportState::ACTIVE &&
!sync_service_->GetActiveDataTypes().Has(syncer::PREFERENCES)));
}
base::Optional<std::string> SharingService::GetDeviceName() const {
if (local_device_name_for_tests_)
return local_device_name_for_tests_;
const syncer::DeviceInfo* local_device_info =
local_device_info_provider_->GetLocalDeviceInfo();
if (local_device_info)
return local_device_info->client_name();
else
return base::nullopt;
}
......@@ -98,14 +98,6 @@ class SharingService : public KeyedService,
// Returns the current state of SharingService.
virtual State GetState() const;
// For testing
void RegisterDeviceInTesting(
std::string device_name,
int capabilities,
SharingDeviceRegistration::RegistrationCallback callback);
SharingSyncPreference* GetSyncPreferences() const;
private:
// Overrides for syncer::SyncServiceObserver.
void OnSyncShutdown(syncer::SyncService* sync) override;
......@@ -115,7 +107,6 @@ class SharingService : public KeyedService,
void OnAckReceived(const std::string& message_id) override;
void RegisterDevice();
void UnregisterDevice();
void OnDeviceRegistered(SharingDeviceRegistrationResult result);
void OnDeviceUnregistered(SharingDeviceRegistrationResult result);
......@@ -131,10 +122,6 @@ class SharingService : public KeyedService,
// in transitioning state.
bool IsSyncDisabled() const;
// Returns |local_device_name_for_tests_| if set, otherwise returns the actual
// device name from |local_device_info_provider_|.
base::Optional<std::string> GetDeviceName() const;
std::unique_ptr<SharingSyncPreference> sync_prefs_;
std::unique_ptr<VapidKeyManager> vapid_key_manager_;
std::unique_ptr<SharingDeviceRegistration> sharing_device_registration_;
......@@ -147,7 +134,6 @@ class SharingService : public KeyedService,
PingMessageHandler ping_message_handler_;
net::BackoffEntry backoff_entry_;
State state_;
base::Optional<std::string> local_device_name_for_tests_;
// Map of random GUID to SendMessageCallback.
std::map<std::string, SendMessageCallback> send_message_callbacks_;
......
......@@ -1075,7 +1075,6 @@ if (!is_android) {
"../browser/sessions/tab_restore_service_browsertest.cc",
"../browser/sessions/tab_restore_service_load_waiter.cc",
"../browser/sessions/tab_restore_service_load_waiter.h",
"../browser/sharing/click_to_call/click_to_call_browsertest.cc",
"../browser/signin/consistency_cookie_browsertest.cc",
"../browser/site_isolation/chrome_site_per_process_browsertest.cc",
"../browser/site_isolation/site_details_browsertest.cc",
......
......@@ -38,16 +38,6 @@ class FakeGCMProfileService::CustomFakeGCMDriver
void OnDispatchMessage(const std::string& app_id,
const IncomingMessage& message);
// instance_id::FakeGCMDriverForInstanceID overrides:
void SendWebPushMessage(const std::string& app_id,
const std::string& authorized_entity,
const std::string& p256dh,
const std::string& auth_secret,
const std::string& fcm_token,
crypto::ECPrivateKey* vapid_key,
gcm::WebPushMessage message,
SendWebPushMessageCallback callback) override;
protected:
// FakeGCMDriver overrides:
void RegisterImpl(const std::string& app_id,
......@@ -162,21 +152,6 @@ void FakeGCMProfileService::CustomFakeGCMDriver::SendImpl(
app_id, receiver_id, message));
}
void FakeGCMProfileService::CustomFakeGCMDriver::SendWebPushMessage(
const std::string& app_id,
const std::string& authorized_entity,
const std::string& p256dh,
const std::string& auth_secret,
const std::string& fcm_token,
crypto::ECPrivateKey* vapid_key,
gcm::WebPushMessage message,
SendWebPushMessageCallback callback) {
if (service_->collect_) {
service_->last_receiver_id_ = fcm_token;
service_->last_web_push_message_ = std::move(message);
}
}
void FakeGCMProfileService::CustomFakeGCMDriver::DoSend(
const std::string& app_id,
const std::string& receiver_id,
......
......@@ -39,10 +39,6 @@ class FakeGCMProfileService : public GCMProfileService {
return last_sent_message_;
}
const WebPushMessage& last_web_push_message() const {
return last_web_push_message_;
}
const std::string& last_receiver_id() const { return last_receiver_id_; }
const std::string& last_registered_app_id() const {
......@@ -73,7 +69,6 @@ class FakeGCMProfileService : public GCMProfileService {
std::list<GCMClient::Result> unregister_responses_;
OutgoingMessage last_sent_message_;
std::string last_receiver_id_;
WebPushMessage last_web_push_message_;
DISALLOW_COPY_AND_ASSIGN(FakeGCMProfileService);
};
......
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