OLD | NEW |
(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 namespace content { |
| 20 namespace background_sync_test_util { |
| 21 |
| 22 namespace { |
| 23 |
| 24 void SetOnlineOnIOThread( |
| 25 const scoped_refptr<BackgroundSyncContext>& sync_context, |
| 26 bool online) { |
| 27 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 28 |
| 29 BackgroundSyncManager* sync_manager = sync_context->background_sync_manager(); |
| 30 BackgroundSyncNetworkObserver* network_observer = |
| 31 sync_manager->GetNetworkObserverForTesting(); |
| 32 if (online) { |
| 33 network_observer->NotifyManagerIfNetworkChangedForTesting( |
| 34 net::NetworkChangeNotifier::CONNECTION_WIFI); |
| 35 } else { |
| 36 network_observer->NotifyManagerIfNetworkChangedForTesting( |
| 37 net::NetworkChangeNotifier::CONNECTION_NONE); |
| 38 } |
| 39 } |
| 40 |
| 41 StoragePartition* GetStoragePartition(WebContents* web_contents) { |
| 42 return BrowserContext::GetStoragePartition(web_contents->GetBrowserContext(), |
| 43 web_contents->GetSiteInstance()); |
| 44 } |
| 45 |
| 46 } // namespace |
| 47 |
| 48 // static |
| 49 void SetIgnoreNetworkChangeNotifier(bool ignore) { |
| 50 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(ignore); |
| 51 } |
| 52 |
| 53 // static |
| 54 void SetOnline(WebContents* web_contents, bool online) { |
| 55 BrowserThread::PostTask( |
| 56 BrowserThread::IO, FROM_HERE, |
| 57 base::Bind(&SetOnlineOnIOThread, |
| 58 base::Unretained(GetStoragePartition(web_contents) |
| 59 ->GetBackgroundSyncContext()), |
| 60 online)); |
| 61 base::RunLoop().RunUntilIdle(); |
| 62 } |
| 63 |
| 64 } // namespace background_sync_test_util |
| 65 |
| 66 } // namespace content |
OLD | NEW |