Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: content/public/test/background_sync_test_util.cc

Issue 1445603003: Extension SW - add test for ServiceWorkerRegistration.sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix after r360068 Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/public/test/background_sync_test_util.h"
6
7 #include "base/run_loop.h"
8 #include "base/task_runner_util.h"
9 #include "content/browser/background_sync/background_sync_manager.h"
10 #include "content/browser/background_sync/background_sync_network_observer.h"
11 #include "content/browser/background_sync/background_sync_registration_handle.h"
12 #include "content/public/browser/background_sync_context.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "content/public/browser/web_contents.h"
17 #include "net/base/network_change_notifier.h"
18
19 using content::BackgroundSyncManager;
20 using content::BackgroundSyncNetworkObserver;
21 using content::BrowserContext;
22 using content::BrowserThread;
23 using content::StoragePartition;
24 using content::WebContents;
25
26 namespace background_sync_test_util {
27
28 namespace {
29
30 void SetOnlineOnIOThread(
31 const scoped_refptr<content::BackgroundSyncContext>& sync_context,
32 bool online) {
33 DCHECK_CURRENTLY_ON(BrowserThread::IO);
34
35 BackgroundSyncManager* sync_manager = sync_context->background_sync_manager();
36 BackgroundSyncNetworkObserver* network_observer =
37 sync_manager->GetNetworkObserverForTesting();
38 if (online) {
39 network_observer->NotifyManagerIfNetworkChangedForTesting(
40 net::NetworkChangeNotifier::CONNECTION_WIFI);
41 } else {
42 network_observer->NotifyManagerIfNetworkChangedForTesting(
43 net::NetworkChangeNotifier::CONNECTION_NONE);
44 }
45 }
46
47 StoragePartition* GetStoragePartition(WebContents* web_contents) {
48 return BrowserContext::GetStoragePartition(web_contents->GetBrowserContext(),
49 web_contents->GetSiteInstance());
50 }
51
52 } // namespace
53
54 // static.
jkarlin 2015/11/17 20:36:15 no period as it's not a sentence
lazyboy 2015/11/17 21:41:28 Done.
55 void SetIgnoreNetworkChangeNotifier(bool ignore) {
56 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(ignore);
jkarlin 2015/11/17 20:36:15 Please update the other tests to use this function
lazyboy 2015/11/17 21:41:28 Done.
57 }
58
59 // static.
jkarlin 2015/11/17 20:36:15 no period as it's not a sentence
lazyboy 2015/11/17 21:41:28 Done.
60 void SetOnline(content::WebContents* web_contents, bool online) {
61 BrowserThread::PostTask(
62 BrowserThread::IO, FROM_HERE,
63 base::Bind(&SetOnlineOnIOThread,
64 base::Unretained(GetStoragePartition(web_contents)
65 ->GetBackgroundSyncContext()),
66 online));
67 base::RunLoop().RunUntilIdle();
68 }
69
70 } // namespace background_sync_test_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698