Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // DisplayInfoProvider unit tests. | 5 // DisplayInfoProvider unit tests. |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "chrome/browser/extensions/api/system_info_display/display_info_provide r.h" | 8 #include "chrome/browser/extensions/api/system_info_display/display_info_provide r.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 const struct TestDisplayInfo kTestingDisplayInfoData[] = { | 34 const struct TestDisplayInfo kTestingDisplayInfoData[] = { |
| 35 {"Display1", "Display Name1", true, true, true, 96.0, 96.0, | 35 {"Display1", "Display Name1", true, true, true, 96.0, 96.0, |
| 36 {0, 0, 1280, 720}, {0, 0, 960, 720}}, | 36 {0, 0, 1280, 720}, {0, 0, 960, 720}}, |
| 37 {"Display2", "Display Name2", true, true, true, 221.0, 221.0, | 37 {"Display2", "Display Name2", true, true, true, 221.0, 221.0, |
| 38 {0, 0, 1280, 720}, {0, 0, 960, 720}} | 38 {0, 0, 1280, 720}, {0, 0, 960, 720}} |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 class TestDisplayInfoProvider : public DisplayInfoProvider { | 41 class TestDisplayInfoProvider : public DisplayInfoProvider { |
| 42 public: | 42 public: |
| 43 virtual bool QueryInfo(DisplayInfo* info) OVERRIDE; | 43 virtual bool QueryInfo() OVERRIDE; |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 virtual ~TestDisplayInfoProvider(); | 46 virtual ~TestDisplayInfoProvider(); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 TestDisplayInfoProvider::~TestDisplayInfoProvider() {} | 49 TestDisplayInfoProvider::~TestDisplayInfoProvider() {} |
| 50 | 50 |
| 51 bool TestDisplayInfoProvider::QueryInfo(DisplayInfo* info) { | 51 bool TestDisplayInfoProvider::QueryInfo() { |
| 52 if (info == NULL) | 52 info_.clear(); |
| 53 return false; | |
| 54 info->clear(); | |
| 55 for (size_t i = 0; i < arraysize(kTestingDisplayInfoData); ++i) { | 53 for (size_t i = 0; i < arraysize(kTestingDisplayInfoData); ++i) { |
| 56 linked_ptr<DisplayUnitInfo> unit(new DisplayUnitInfo()); | 54 linked_ptr<DisplayUnitInfo> unit(new DisplayUnitInfo()); |
| 57 unit->id = kTestingDisplayInfoData[i].id; | 55 unit->id = kTestingDisplayInfoData[i].id; |
| 58 unit->name = kTestingDisplayInfoData[i].name; | 56 unit->name = kTestingDisplayInfoData[i].name; |
| 59 unit->is_enabled = kTestingDisplayInfoData[i].is_enabled; | 57 unit->is_enabled = kTestingDisplayInfoData[i].is_enabled; |
| 60 unit->is_primary = kTestingDisplayInfoData[i].is_primary; | 58 unit->is_primary = kTestingDisplayInfoData[i].is_primary; |
| 61 unit->is_internal = kTestingDisplayInfoData[i].is_internal; | 59 unit->is_internal = kTestingDisplayInfoData[i].is_internal; |
| 62 unit->dpi_x = kTestingDisplayInfoData[i].dpi_x; | 60 unit->dpi_x = kTestingDisplayInfoData[i].dpi_x; |
| 63 unit->dpi_y = kTestingDisplayInfoData[i].dpi_y; | 61 unit->dpi_y = kTestingDisplayInfoData[i].dpi_y; |
| 64 unit->bounds.left = kTestingDisplayInfoData[i].bounds.left; | 62 unit->bounds.left = kTestingDisplayInfoData[i].bounds.left; |
| 65 unit->bounds.top = kTestingDisplayInfoData[i].bounds.top; | 63 unit->bounds.top = kTestingDisplayInfoData[i].bounds.top; |
| 66 unit->bounds.width = kTestingDisplayInfoData[i].bounds.width; | 64 unit->bounds.width = kTestingDisplayInfoData[i].bounds.width; |
| 67 unit->bounds.height = kTestingDisplayInfoData[i].bounds.height; | 65 unit->bounds.height = kTestingDisplayInfoData[i].bounds.height; |
| 68 unit->work_area.left = kTestingDisplayInfoData[i].work_area.left; | 66 unit->work_area.left = kTestingDisplayInfoData[i].work_area.left; |
| 69 unit->work_area.top = kTestingDisplayInfoData[i].work_area.top; | 67 unit->work_area.top = kTestingDisplayInfoData[i].work_area.top; |
| 70 unit->work_area.width = kTestingDisplayInfoData[i].work_area.width; | 68 unit->work_area.width = kTestingDisplayInfoData[i].work_area.width; |
| 71 unit->work_area.height = kTestingDisplayInfoData[i].work_area.height; | 69 unit->work_area.height = kTestingDisplayInfoData[i].work_area.height; |
| 72 info->push_back(unit); | 70 info_.push_back(unit); |
| 73 } | 71 } |
| 74 return true; | 72 return true; |
| 75 } | 73 } |
| 76 | 74 |
| 77 class DisplayInfoProviderTest : public testing::Test { | 75 class DisplayInfoProviderTest : public testing::Test { |
| 78 public: | 76 public: |
| 79 DisplayInfoProviderTest(); | 77 DisplayInfoProviderTest(); |
| 80 | 78 |
| 81 protected: | 79 protected: |
| 82 scoped_refptr<TestDisplayInfoProvider> display_info_provider_; | 80 scoped_refptr<TestDisplayInfoProvider> display_info_provider_; |
| 83 }; | 81 }; |
| 84 | 82 |
| 85 DisplayInfoProviderTest::DisplayInfoProviderTest() | 83 DisplayInfoProviderTest::DisplayInfoProviderTest() |
| 86 : display_info_provider_(new TestDisplayInfoProvider()) { | 84 : display_info_provider_(new TestDisplayInfoProvider()) { |
| 87 } | 85 } |
| 88 | 86 |
| 89 TEST_F(DisplayInfoProviderTest, QueryDisplayInfo) { | 87 TEST_F(DisplayInfoProviderTest, QueryDisplayInfo) { |
| 90 scoped_ptr<DisplayInfo> display_info(new DisplayInfo()); | 88 EXPECT_TRUE(display_info_provider_->QueryInfo()); |
| 91 EXPECT_TRUE(display_info_provider_->QueryInfo(display_info.get())); | 89 const DisplayInfo& display_info = display_info_provider_->display_info(); |
|
Jeffrey Yasskin
2013/07/08 19:09:49
FWIW, this doesn't test anything that runs in the
Haojian Wu
2013/07/09 13:45:04
Your suggestion reminds me that the unit_tests of
Jeffrey Yasskin
2013/07/09 18:19:59
Yeah, we should remove them and replace them (like
| |
| 92 EXPECT_EQ(arraysize(kTestingDisplayInfoData), display_info->size()); | 90 EXPECT_EQ(arraysize(kTestingDisplayInfoData), display_info.size()); |
| 93 for (size_t i = 0; i < arraysize(kTestingDisplayInfoData); ++i) { | 91 for (size_t i = 0; i < arraysize(kTestingDisplayInfoData); ++i) { |
| 94 const linked_ptr<api::system_info_display::DisplayUnitInfo> unit = | 92 const linked_ptr<api::system_info_display::DisplayUnitInfo> unit = |
| 95 (*display_info.get())[i]; | 93 display_info[i]; |
| 96 EXPECT_EQ(kTestingDisplayInfoData[i].id, unit->id); | 94 EXPECT_EQ(kTestingDisplayInfoData[i].id, unit->id); |
| 97 EXPECT_EQ(kTestingDisplayInfoData[i].name, unit->name); | 95 EXPECT_EQ(kTestingDisplayInfoData[i].name, unit->name); |
| 98 EXPECT_DOUBLE_EQ(kTestingDisplayInfoData[i].dpi_x, unit->dpi_x); | 96 EXPECT_DOUBLE_EQ(kTestingDisplayInfoData[i].dpi_x, unit->dpi_x); |
| 99 EXPECT_DOUBLE_EQ(kTestingDisplayInfoData[i].dpi_y, unit->dpi_y); | 97 EXPECT_DOUBLE_EQ(kTestingDisplayInfoData[i].dpi_y, unit->dpi_y); |
| 100 EXPECT_EQ(kTestingDisplayInfoData[i].is_enabled, unit->is_enabled); | 98 EXPECT_EQ(kTestingDisplayInfoData[i].is_enabled, unit->is_enabled); |
| 101 EXPECT_EQ(kTestingDisplayInfoData[i].is_internal, unit->is_internal); | 99 EXPECT_EQ(kTestingDisplayInfoData[i].is_internal, unit->is_internal); |
| 102 EXPECT_EQ(kTestingDisplayInfoData[i].is_primary, unit->is_primary); | 100 EXPECT_EQ(kTestingDisplayInfoData[i].is_primary, unit->is_primary); |
| 103 EXPECT_EQ(kTestingDisplayInfoData[i].bounds.left, unit->bounds.left); | 101 EXPECT_EQ(kTestingDisplayInfoData[i].bounds.left, unit->bounds.left); |
| 104 EXPECT_EQ(kTestingDisplayInfoData[i].bounds.top, unit->bounds.top); | 102 EXPECT_EQ(kTestingDisplayInfoData[i].bounds.top, unit->bounds.top); |
| 105 EXPECT_EQ(kTestingDisplayInfoData[i].bounds.width, unit->bounds.width); | 103 EXPECT_EQ(kTestingDisplayInfoData[i].bounds.width, unit->bounds.width); |
| 106 EXPECT_EQ(kTestingDisplayInfoData[i].bounds.height, unit->bounds.height); | 104 EXPECT_EQ(kTestingDisplayInfoData[i].bounds.height, unit->bounds.height); |
| 107 EXPECT_EQ(kTestingDisplayInfoData[i].work_area.left, unit->work_area.left); | 105 EXPECT_EQ(kTestingDisplayInfoData[i].work_area.left, unit->work_area.left); |
| 108 EXPECT_EQ(kTestingDisplayInfoData[i].work_area.top, unit->work_area.top); | 106 EXPECT_EQ(kTestingDisplayInfoData[i].work_area.top, unit->work_area.top); |
| 109 EXPECT_EQ(kTestingDisplayInfoData[i].work_area.width, | 107 EXPECT_EQ(kTestingDisplayInfoData[i].work_area.width, |
| 110 unit->work_area.width); | 108 unit->work_area.width); |
| 111 EXPECT_EQ(kTestingDisplayInfoData[i].work_area.height, | 109 EXPECT_EQ(kTestingDisplayInfoData[i].work_area.height, |
| 112 unit->work_area.height); | 110 unit->work_area.height); |
| 113 } | 111 } |
| 114 } | 112 } |
| 115 | 113 |
| 116 } // namespace extensions | 114 } // namespace extensions |
| OLD | NEW |