Commit 33e9c5de authored by Jeffrey Cohen's avatar Jeffrey Cohen Committed by Commit Bot

[SendTabToSelf] ensure sync is disabled during paused state

Bug: 1141839
Change-Id: I1da008817c240679b37193b1e2bb13faf0036a52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2530905
Commit-Queue: Jeffrey Cohen <jeffreycohen@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827043}
parent d887e813
......@@ -6,8 +6,10 @@
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h"
#include "chrome/browser/sync/send_tab_to_self_sync_service_factory.h"
#include "chrome/browser/sync/test/integration/bookmarks_helper.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/send_tab_to_self_helper.h"
#include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/browser.h"
#include "components/history/core/browser/history_service.h"
......@@ -147,4 +149,47 @@ IN_PROC_BROWSER_TEST_F(SingleClientSendTabToSelfSyncTest,
.Wait());
}
IN_PROC_BROWSER_TEST_F(SingleClientSendTabToSelfSyncTest,
ShouldNotUploadInSyncPausedState) {
const GURL kUrl("https://www.example.com");
const std::string kTitle("example");
const base::Time kTime = base::Time::FromDoubleT(1);
const std::string kTargetDeviceSyncCacheGuid("target");
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(GetSyncService(0)->IsSyncFeatureActive());
// Enter the sync paused state.
GetClient(0)->EnterSyncPausedStateForPrimaryAccount();
ASSERT_TRUE(GetSyncService(0)->GetAuthError().IsPersistentError());
send_tab_to_self::SendTabToSelfModel* model =
SendTabToSelfSyncServiceFactory::GetForProfile(GetProfile(0))
->GetSendTabToSelfModel();
ASSERT_FALSE(
model->AddEntry(kUrl, kTitle, kTime, kTargetDeviceSyncCacheGuid));
EXPECT_FALSE(send_tab_to_self::ShouldOfferFeature(
GetBrowser(0)->tab_strip_model()->GetActiveWebContents()));
// Clear the "Sync paused" state again.
GetClient(0)->ExitSyncPausedStateForPrimaryAccount();
ASSERT_TRUE(GetSyncService(0)->IsSyncFeatureActive());
// Just checking that we don't see test_event isn't very convincing yet,
// because it may simply not have reached the server yet. So let's send
// something else through the system that we can wait on before checking.
ASSERT_TRUE(
bookmarks_helper::AddURL(0, "What are you syncing about?",
GURL("https://google.com/synced-bookmark-1")));
ASSERT_TRUE(ServerCountMatchStatusChecker(syncer::BOOKMARKS, 1).Wait());
// Repurpose the deleted checker to ensure url wasnt added.
EXPECT_TRUE(send_tab_to_self_helper::SendTabToSelfUrlDeletedChecker(
SendTabToSelfSyncServiceFactory::GetForProfile(GetProfile(0)),
GURL(kUrl))
.Wait());
}
} // namespace
......@@ -36,6 +36,25 @@ SendTabToSelfModelTypeController::~SendTabToSelfModelTypeController() {
sync_service_->RemoveObserver(this);
}
void SendTabToSelfModelTypeController::Stop(
syncer::ShutdownReason shutdown_reason,
StopCallback callback) {
DCHECK(CalledOnValidThread());
switch (shutdown_reason) {
case syncer::STOP_SYNC:
// Special case: We want to clear all data even when Sync is stopped
// temporarily. This is also needed to make sure the feature stops being
// offered to the user, because predicates like IsUserSyncTypeActive()
// should return false upon stop.
shutdown_reason = syncer::DISABLE_SYNC;
break;
case syncer::DISABLE_SYNC:
case syncer::BROWSER_SHUTDOWN:
break;
}
ModelTypeController::Stop(shutdown_reason, std::move(callback));
}
syncer::DataTypeController::PreconditionState
SendTabToSelfModelTypeController::GetPreconditionState() const {
DCHECK(CalledOnValidThread());
......
......@@ -30,6 +30,10 @@ class SendTabToSelfModelTypeController : public syncer::ModelTypeController,
delegate_for_transport_mode);
~SendTabToSelfModelTypeController() override;
// DataTypeController overrides.
void Stop(syncer::ShutdownReason shutdown_reason,
StopCallback callback) override;
// DataTypeController overrides.
PreconditionState GetPreconditionState() const override;
......
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