OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 <vector> |
| 6 |
| 7 #include "base/base_paths.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/path_service.h" |
| 12 #include "content/browser/gpu/gpu_switching_list.h" |
| 13 #include "content/public/common/gpu_info.h" |
| 14 #include "content/public/common/gpu_switching_option.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 const char kOsVersion[] = "10.6.4"; |
| 18 |
| 19 namespace content { |
| 20 |
| 21 class GpuSwitchingListTest : public testing::Test { |
| 22 public: |
| 23 GpuSwitchingListTest() { } |
| 24 |
| 25 virtual ~GpuSwitchingListTest() { } |
| 26 |
| 27 const GPUInfo& gpu_info() const { |
| 28 return gpu_info_; |
| 29 } |
| 30 |
| 31 protected: |
| 32 virtual void SetUp() { |
| 33 gpu_info_.gpu.vendor_id = 0x10de; |
| 34 gpu_info_.gpu.device_id = 0x0640; |
| 35 gpu_info_.driver_vendor = "NVIDIA"; |
| 36 gpu_info_.driver_version = "1.6.18"; |
| 37 gpu_info_.driver_date = "7-14-2009"; |
| 38 gpu_info_.machine_model = "MacBookPro 7.1"; |
| 39 gpu_info_.gl_vendor = "NVIDIA Corporation"; |
| 40 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; |
| 41 gpu_info_.performance_stats.graphics = 5.0; |
| 42 gpu_info_.performance_stats.gaming = 5.0; |
| 43 gpu_info_.performance_stats.overall = 5.0; |
| 44 } |
| 45 |
| 46 virtual void TearDown() { |
| 47 } |
| 48 |
| 49 private: |
| 50 GPUInfo gpu_info_; |
| 51 }; |
| 52 |
| 53 TEST_F(GpuSwitchingListTest, CurrentSwitchingListValidation) { |
| 54 base::FilePath data_file; |
| 55 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file)); |
| 56 data_file = |
| 57 data_file.Append(FILE_PATH_LITERAL("content")) |
| 58 .Append(FILE_PATH_LITERAL("browser")) |
| 59 .Append(FILE_PATH_LITERAL("gpu")) |
| 60 .Append(FILE_PATH_LITERAL("gpu_switching_list.json")); |
| 61 ASSERT_TRUE(file_util::PathExists(data_file)); |
| 62 int64 data_file_size64 = 0; |
| 63 ASSERT_TRUE(file_util::GetFileSize(data_file, &data_file_size64)); |
| 64 int data_file_size = static_cast<int>(data_file_size64); |
| 65 scoped_array<char> data(new char[data_file_size]); |
| 66 ASSERT_EQ(data_file_size, |
| 67 file_util::ReadFile(data_file, data.get(), data_file_size)); |
| 68 std::string json_string(data.get(), data_file_size); |
| 69 scoped_ptr<GpuSwitchingList> switching_list(GpuSwitchingList::Create()); |
| 70 EXPECT_TRUE(switching_list->LoadList(json_string, GpuControlList::kAllOs)); |
| 71 EXPECT_FALSE(switching_list->contains_unknown_fields()); |
| 72 } |
| 73 |
| 74 TEST_F(GpuSwitchingListTest, GpuSwitching) { |
| 75 const std::string json = |
| 76 "{\n" |
| 77 " \"name\": \"gpu switching list\",\n" |
| 78 " \"version\": \"0.1\",\n" |
| 79 " \"entries\": [\n" |
| 80 " {\n" |
| 81 " \"id\": 1,\n" |
| 82 " \"os\": {\n" |
| 83 " \"type\": \"macosx\"\n" |
| 84 " },\n" |
| 85 " \"features\": [\n" |
| 86 " \"force_discrete\"\n" |
| 87 " ]\n" |
| 88 " },\n" |
| 89 " {\n" |
| 90 " \"id\": 2,\n" |
| 91 " \"os\": {\n" |
| 92 " \"type\": \"win\"\n" |
| 93 " },\n" |
| 94 " \"features\": [\n" |
| 95 " \"force_integrated\"\n" |
| 96 " ]\n" |
| 97 " }\n" |
| 98 " ]\n" |
| 99 "}"; |
| 100 |
| 101 scoped_ptr<GpuSwitchingList> switching_list(GpuSwitchingList::Create()); |
| 102 EXPECT_TRUE(switching_list->LoadList(json, GpuControlList::kAllOs)); |
| 103 int switching = switching_list->MakeDecision( |
| 104 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 105 EXPECT_EQ(GPU_SWITCHING_OPTION_FORCE_DISCRETE, |
| 106 static_cast<GpuSwitchingOption>(switching)); |
| 107 std::vector<uint32> entries; |
| 108 switching_list->GetDecisionEntries(&entries, false); |
| 109 ASSERT_EQ(1u, entries.size()); |
| 110 EXPECT_EQ(1u, entries[0]); |
| 111 |
| 112 switching_list.reset(GpuSwitchingList::Create()); |
| 113 EXPECT_TRUE(switching_list->LoadList(json, GpuControlList::kAllOs)); |
| 114 switching = switching_list->MakeDecision( |
| 115 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 116 EXPECT_EQ(GPU_SWITCHING_OPTION_FORCE_INTEGRATED, |
| 117 static_cast<GpuSwitchingOption>(switching)); |
| 118 switching_list->GetDecisionEntries(&entries, false); |
| 119 ASSERT_EQ(1u, entries.size()); |
| 120 EXPECT_EQ(2u, entries[0]); |
| 121 } |
| 122 |
| 123 } // namespace content |
| 124 |
OLD | NEW |