Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / test_util.cc
bloba4c31f70fffadbd31447ce6376316286eb9b0d1e
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/chromeos/drive/test_util.h"
7 #include <string>
9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/testing_pref_service.h"
12 #include "base/run_loop.h"
13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/chromeos/drive/drive.pb.h"
15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/browser_thread.h"
18 namespace drive {
20 namespace test_util {
22 namespace {
24 // This class is used to monitor if any task is posted to a message loop.
25 class TaskObserver : public base::MessageLoop::TaskObserver {
26 public:
27 TaskObserver() : posted_(false) {}
28 virtual ~TaskObserver() {}
30 // MessageLoop::TaskObserver overrides.
31 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
33 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {
34 posted_ = true;
37 // Returns true if any task was posted.
38 bool posted() const { return posted_; }
40 private:
41 bool posted_;
42 DISALLOW_COPY_AND_ASSIGN(TaskObserver);
45 } // namespace
47 void RunBlockingPoolTask() {
48 while (true) {
49 content::BrowserThread::GetBlockingPool()->FlushForTesting();
51 TaskObserver task_observer;
52 base::MessageLoop::current()->AddTaskObserver(&task_observer);
53 base::RunLoop().RunUntilIdle();
54 base::MessageLoop::current()->RemoveTaskObserver(&task_observer);
55 if (!task_observer.posted())
56 break;
60 void RegisterDrivePrefs(PrefRegistrySimple* pref_registry) {
61 pref_registry->RegisterBooleanPref(
62 prefs::kDisableDrive,
63 false);
64 pref_registry->RegisterBooleanPref(
65 prefs::kDisableDriveOverCellular,
66 true);
67 pref_registry->RegisterBooleanPref(
68 prefs::kDisableDriveHostedFiles,
69 false);
72 FakeNetworkChangeNotifier::FakeNetworkChangeNotifier()
73 : type_(CONNECTION_WIFI) {
76 void FakeNetworkChangeNotifier::SetConnectionType(ConnectionType type) {
77 type_ = type;
78 NotifyObserversOfConnectionTypeChange();
81 net::NetworkChangeNotifier::ConnectionType
82 FakeNetworkChangeNotifier::GetCurrentConnectionType() const {
83 return type_;
86 } // namespace test_util
87 } // namespace drive