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

Side by Side Diff: chrome/browser/chromeos/net/network_throttling_observer_unittest.cc

Issue 2466693002: [Re-land] Add network throttling as enterprise policy (Closed)
Patch Set: Created 4 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 (c) 2016 The Chromium Authors. All rights reserved.
Lei Zhang 2016/11/03 19:38:39 nit: no (c)
kirtika1 2016/11/04 00:27:32 Done.
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 <memory>
6
7 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/chromeos/net/network_throttling_observer.h"
9 #include "chrome/common/pref_names.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/mock_shill_manager_client.h"
12 #include "chromeos/network/network_state_handler.h"
13 #include "components/prefs/pref_registry_simple.h"
14 #include "components/prefs/testing_pref_service.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 using testing::_;
19 using testing::Mock;
20 using testing::NiceMock;
21
22 namespace chromeos {
23
24 namespace test {
25
26 class NetworkThrottlingObserverTest : public ::testing::Test {
27 public:
28 NetworkThrottlingObserverTest() : message_loop_(new base::MessageLoop()) {
29 DBusThreadManager::Initialize();
30 std::unique_ptr<DBusThreadManagerSetter> dbus_setter =
31 DBusThreadManager::GetSetterForTesting();
Lei Zhang 2016/11/03 19:38:39 Previously, you had: DBusThreadManager::Initializ
kirtika1 2016/11/04 00:27:32 Done.
32 // Owned by DBusThreadManager, which takes care of cleaning it
33 mock_manager_client_ = new NiceMock<MockShillManagerClient>();
34 dbus_setter->SetShillManagerClient(
35 std::unique_ptr<ShillManagerClient>(mock_manager_client_));
36 NetworkStateHandler::InitializeForTest();
Lei Zhang 2016/11/03 19:38:39 You need to take the returned pointer and free it
kirtika1 2016/11/04 00:27:32 Done.
37 NetworkHandler::Initialize();
38 local_state_ = new TestingPrefServiceSimple();
Lei Zhang 2016/11/03 19:38:39 Who frees this? Did you try freeing it before? Did
39 local_state_->registry()->RegisterDictionaryPref(
40 prefs::kNetworkThrottlingEnabled);
41 observer_ = base::MakeUnique<NetworkThrottlingObserver>(local_state_);
42 }
43
44 ~NetworkThrottlingObserverTest() override {
45 NetworkHandler::Shutdown();
46 DBusThreadManager::Shutdown();
47 }
48
49 std::unique_ptr<base::MessageLoop> message_loop_;
Lei Zhang 2016/11/03 19:38:39 Just drop the std::unique_ptr.
kirtika1 2016/11/04 00:27:32 Done.
50 std::unique_ptr<NetworkThrottlingObserver> observer_;
51 TestingPrefServiceSimple* local_state_;
52 MockShillManagerClient* mock_manager_client_;
53
54 private:
55 DISALLOW_COPY_AND_ASSIGN(NetworkThrottlingObserverTest);
56 };
57
58 TEST_F(NetworkThrottlingObserverTest, ThrottlingChangeCallsShill) {
59 // Test that a change in the throttling policy value leads to
60 // shill_manager_client being called.
61 base::DictionaryValue updated_throttling_policy;
62 bool enabled = true;
63 uint32_t upload_rate = 1200;
64 uint32_t download_rate = 2000;
65 updated_throttling_policy.SetBoolean("enabled", enabled);
66 updated_throttling_policy.SetInteger("upload_rate_kbits", upload_rate);
67 updated_throttling_policy.SetInteger("download_rate_kbits", download_rate);
68 EXPECT_CALL(
69 *mock_manager_client_,
70 SetNetworkThrottlingStatus(enabled, upload_rate, download_rate, _, _))
71 .Times(1);
72 local_state_->Set(prefs::kNetworkThrottlingEnabled,
73 updated_throttling_policy);
74 Mock::VerifyAndClearExpectations(mock_manager_client_);
75
76 // Clearing the preference should disable throttling
77 EXPECT_CALL(*mock_manager_client_,
78 SetNetworkThrottlingStatus(false, 0, 0, _, _))
79 .Times(1);
80 local_state_->ClearPref(prefs::kNetworkThrottlingEnabled);
81 }
82
83 } // namespace test
84 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698