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