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 "sync/util/get_session_name.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 #if defined(OS_CHROMEOS) 13 #include "base/command_line.h" 14 #include "chromeos/chromeos_switches.h" 15 #endif // OS_CHROMEOS 16 17 namespace syncer { 18 19 namespace { 20 21 class GetSessionNameTest : public ::testing::Test { 22 public: 23 void SetSessionNameAndQuit(const std::string& session_name) { 24 session_name_ = session_name; 25 message_loop_.Quit(); 26 } 27 28 protected: 29 base::MessageLoop message_loop_; 30 std::string session_name_; 31 }; 32 33 // Call GetSessionNameSynchronouslyForTesting and make sure its return 34 // value looks sane. 35 TEST_F(GetSessionNameTest, GetSessionNameSynchronously) { 36 const std::string& session_name = GetSessionNameSynchronouslyForTesting(); 37 EXPECT_FALSE(session_name.empty()); 38 } 39 40 #if defined(OS_CHROMEOS) 41 42 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type 43 // is "lumpy-signed-mp-v2keys" and make sure the return value is "Chromebook". 44 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebook) { 45 // This test cannot be run on a real CrOs device, since it will already have a 46 // board type, and we cannot override it. 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(); 55 EXPECT_EQ("Chromebook", session_name); 56 } 57 58 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type 59 // is "stumpy-signed-mp-v2keys" and make sure the return value is "Chromebox". 60 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebox) { 61 // This test cannot be run on a real CrOs device, since it will already have a 62 // board type, and we cannot override it. 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(); 71 EXPECT_EQ("Chromebox", session_name); 72 } 73 74 #endif // OS_CHROMEOS 75 76 // Calls GetSessionName and runs the message loop until it comes back 77 // with a session name. Makes sure the returned session name is equal 78 // to the return value of GetSessionNameSynchronouslyForTesting(). 79 TEST_F(GetSessionNameTest, GetSessionName) { 80 GetSessionName(message_loop_.message_loop_proxy(), 81 base::Bind(&GetSessionNameTest::SetSessionNameAndQuit, 82 base::Unretained(this))); 83 message_loop_.Run(); 84 EXPECT_EQ(session_name_, GetSessionNameSynchronouslyForTesting()); 85 } 86 87 } // namespace 88 89 } // namespace syncer 90