OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/sys_info.h" |
9 #include "sync/util/get_session_name.h" | 10 #include "sync/util/get_session_name.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 #if defined(OS_CHROMEOS) | 13 #if defined(OS_CHROMEOS) |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "chromeos/chromeos_switches.h" | 15 #include "chromeos/chromeos_switches.h" |
15 #endif // OS_CHROMEOS | 16 #endif // OS_CHROMEOS |
16 | 17 |
17 namespace syncer { | 18 namespace syncer { |
18 | 19 |
(...skipping 16 matching lines...) Expand all Loading... |
35 TEST_F(GetSessionNameTest, GetSessionNameSynchronously) { | 36 TEST_F(GetSessionNameTest, GetSessionNameSynchronously) { |
36 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); | 37 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); |
37 EXPECT_FALSE(session_name.empty()); | 38 EXPECT_FALSE(session_name.empty()); |
38 } | 39 } |
39 | 40 |
40 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
41 | 42 |
42 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type | 43 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type |
43 // is "lumpy-signed-mp-v2keys" and make sure the return value is "Chromebook". | 44 // is "lumpy-signed-mp-v2keys" and make sure the return value is "Chromebook". |
44 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebook) { | 45 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebook) { |
45 // This test cannot be run on a real CrOs device, since it will already have a | 46 const char* kLsbRelease = "CHROMEOS_RELEASE_BOARD=lumpy-signed-mp-v2keys\n"; |
46 // board type, and we cannot override it. | 47 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); |
47 // TODO(rsimha): Rewrite this test once http://crbug.com/126732 is fixed. | |
48 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
49 if (command_line->HasSwitch(chromeos::switches::kChromeOSReleaseBoard)) | |
50 return; | |
51 | |
52 command_line->AppendSwitchASCII(chromeos::switches::kChromeOSReleaseBoard, | |
53 "lumpy-signed-mp-v2keys"); | |
54 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); | 48 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); |
55 EXPECT_EQ("Chromebook", session_name); | 49 EXPECT_EQ("Chromebook", session_name); |
56 } | 50 } |
57 | 51 |
58 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type | 52 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type |
59 // is "stumpy-signed-mp-v2keys" and make sure the return value is "Chromebox". | 53 // is "stumpy-signed-mp-v2keys" and make sure the return value is "Chromebox". |
60 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebox) { | 54 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebox) { |
61 // This test cannot be run on a real CrOs device, since it will already have a | 55 const char* kLsbRelease = "CHROMEOS_RELEASE_BOARD=stumpy-signed-mp-v2keys\n"; |
62 // board type, and we cannot override it. | 56 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); |
63 // TODO(rsimha): Rewrite this test once http://crbug.com/126732 is fixed. | |
64 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
65 if (command_line->HasSwitch(chromeos::switches::kChromeOSReleaseBoard)) | |
66 return; | |
67 | |
68 command_line->AppendSwitchASCII(chromeos::switches::kChromeOSReleaseBoard, | |
69 "stumpy-signed-mp-v2keys"); | |
70 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); | 57 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); |
71 EXPECT_EQ("Chromebox", session_name); | 58 EXPECT_EQ("Chromebox", session_name); |
72 } | 59 } |
73 | 60 |
74 #endif // OS_CHROMEOS | 61 #endif // OS_CHROMEOS |
75 | 62 |
76 // Calls GetSessionName and runs the message loop until it comes back | 63 // Calls GetSessionName and runs the message loop until it comes back |
77 // with a session name. Makes sure the returned session name is equal | 64 // with a session name. Makes sure the returned session name is equal |
78 // to the return value of GetSessionNameSynchronouslyForTesting(). | 65 // to the return value of GetSessionNameSynchronouslyForTesting(). |
79 TEST_F(GetSessionNameTest, GetSessionName) { | 66 TEST_F(GetSessionNameTest, GetSessionName) { |
80 GetSessionName(message_loop_.message_loop_proxy(), | 67 GetSessionName(message_loop_.message_loop_proxy(), |
81 base::Bind(&GetSessionNameTest::SetSessionNameAndQuit, | 68 base::Bind(&GetSessionNameTest::SetSessionNameAndQuit, |
82 base::Unretained(this))); | 69 base::Unretained(this))); |
83 message_loop_.Run(); | 70 message_loop_.Run(); |
84 EXPECT_EQ(session_name_, GetSessionNameSynchronouslyForTesting()); | 71 EXPECT_EQ(session_name_, GetSessionNameSynchronouslyForTesting()); |
85 } | 72 } |
86 | 73 |
87 } // namespace | 74 } // namespace |
88 | 75 |
89 } // namespace syncer | 76 } // namespace syncer |
OLD | NEW |