Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / task_management / providers / browser_process_task_unittest.cc
blob4350e9f287071e132238b87285a530805f32e9a6
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.
5 #include "chrome/browser/task_management/providers/browser_process_task_provider.h"
6 #include "chrome/grit/generated_resources.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/base/l10n/l10n_util.h"
10 namespace task_management {
12 class BrowserProcessTaskProviderTest
13 : public testing::Test,
14 public TaskProviderObserver {
15 public:
16 BrowserProcessTaskProviderTest()
17 : provided_task_(nullptr) {
20 ~BrowserProcessTaskProviderTest() override {}
22 // task_management::TaskProviderObserver:
23 void TaskAdded(Task* task) override {
24 provided_task_ = task;
26 void TaskRemoved(Task* task) override {
27 // This will never be called in the case of a browser process task provider.
28 FAIL();
31 protected:
32 Task* provided_task_;
34 private:
35 DISALLOW_COPY_AND_ASSIGN(BrowserProcessTaskProviderTest);
38 // Tests the browser process task provider and browser process task itself.
39 TEST_F(BrowserProcessTaskProviderTest, TestObserving) {
40 BrowserProcessTaskProvider provider;
41 EXPECT_EQ(nullptr, provided_task_);
42 provider.SetObserver(this);
43 EXPECT_NE(nullptr, provided_task_);
44 provider.ClearObserver();
45 EXPECT_NE(nullptr, provided_task_);
48 // Testing retrieving the task from the provider using the ids of a URL request.
49 TEST_F(BrowserProcessTaskProviderTest, GetTaskOfUrlRequest) {
50 BrowserProcessTaskProvider provider;
51 EXPECT_EQ(nullptr, provided_task_);
52 provider.SetObserver(this);
53 EXPECT_NE(nullptr, provided_task_);
55 Task* result = provider.GetTaskOfUrlRequest(1, 0, 0);
56 EXPECT_EQ(nullptr, result);
57 result = provider.GetTaskOfUrlRequest(0, -1, 0);
58 EXPECT_EQ(provided_task_, result);
61 // Test the provided browser process task itself.
62 TEST_F(BrowserProcessTaskProviderTest, TestProvidedTask) {
63 BrowserProcessTaskProvider provider;
64 EXPECT_EQ(nullptr, provided_task_);
65 provider.SetObserver(this);
66 ASSERT_NE(nullptr, provided_task_);
68 EXPECT_EQ(base::GetCurrentProcessHandle(), provided_task_->process_handle());
69 EXPECT_FALSE(provided_task_->ReportsWebCacheStats());
70 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT),
71 provided_task_->title());
72 EXPECT_EQ(Task::BROWSER, provided_task_->GetType());
73 EXPECT_EQ(0, provided_task_->GetChildProcessUniqueID());
74 EXPECT_EQ(0, provided_task_->GetRoutingID());
75 const int received_bytes = 1024;
76 EXPECT_FALSE(provided_task_->ReportsNetworkUsage());
77 EXPECT_EQ(-1, provided_task_->network_usage());
78 provided_task_->OnNetworkBytesRead(received_bytes);
79 // Do a refresh with a 1-second update time.
80 provided_task_->Refresh(base::TimeDelta::FromSeconds(1));
81 EXPECT_TRUE(provided_task_->ReportsNetworkUsage());
82 EXPECT_EQ(received_bytes, provided_task_->network_usage());
85 } // namespace task_management