| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "base/sys_info.h" | |
| 11 #include "build/build_config.h" | |
| 12 #include "sync/util/get_session_name.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 #if defined(OS_CHROMEOS) | |
| 16 #include "base/command_line.h" | |
| 17 #include "chromeos/chromeos_switches.h" | |
| 18 #endif // OS_CHROMEOS | |
| 19 | |
| 20 namespace syncer { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 class GetSessionNameTest : public ::testing::Test { | |
| 25 public: | |
| 26 void SetSessionNameAndQuit(const std::string& session_name) { | |
| 27 session_name_ = session_name; | |
| 28 message_loop_.QuitWhenIdle(); | |
| 29 } | |
| 30 | |
| 31 protected: | |
| 32 base::MessageLoop message_loop_; | |
| 33 std::string session_name_; | |
| 34 }; | |
| 35 | |
| 36 // Call GetSessionNameSynchronouslyForTesting and make sure its return | |
| 37 // value looks sane. | |
| 38 TEST_F(GetSessionNameTest, GetSessionNameSynchronously) { | |
| 39 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); | |
| 40 EXPECT_FALSE(session_name.empty()); | |
| 41 } | |
| 42 | |
| 43 #if defined(OS_CHROMEOS) | |
| 44 | |
| 45 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type | |
| 46 // is CHROMEBOOK and make sure the return value is "Chromebook". | |
| 47 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebook) { | |
| 48 const char* kLsbRelease = "DEVICETYPE=CHROMEBOOK\n"; | |
| 49 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | |
| 50 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); | |
| 51 EXPECT_EQ("Chromebook", session_name); | |
| 52 } | |
| 53 | |
| 54 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type | |
| 55 // is a CHROMEBOX and make sure the return value is "Chromebox". | |
| 56 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebox) { | |
| 57 const char* kLsbRelease = "DEVICETYPE=CHROMEBOX\n"; | |
| 58 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | |
| 59 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); | |
| 60 EXPECT_EQ("Chromebox", session_name); | |
| 61 } | |
| 62 | |
| 63 #endif // OS_CHROMEOS | |
| 64 | |
| 65 // Calls GetSessionName and runs the message loop until it comes back | |
| 66 // with a session name. Makes sure the returned session name is equal | |
| 67 // to the return value of GetSessionNameSynchronouslyForTesting(). | |
| 68 TEST_F(GetSessionNameTest, GetSessionName) { | |
| 69 GetSessionName(message_loop_.task_runner(), | |
| 70 base::Bind(&GetSessionNameTest::SetSessionNameAndQuit, | |
| 71 base::Unretained(this))); | |
| 72 base::RunLoop().Run(); | |
| 73 EXPECT_EQ(session_name_, GetSessionNameSynchronouslyForTesting()); | |
| 74 } | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 78 } // namespace syncer | |
| OLD | NEW |