OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
6 #error "This file requires ARC support." | |
7 #endif | |
8 | |
9 #import "remoting/ios/ui/host_list_view_controller.h" | |
10 | |
11 #import "base/compiler_specific.h" | |
12 #import "testing/gtest_mac.h" | |
13 | |
14 #import "remoting/ios/host.h" | |
15 #import "remoting/ios/host_refresh_test_helper.h" | |
16 #import "remoting/ios/ui/host_view_controller.h" | |
17 | |
18 namespace remoting { | |
19 | |
20 class HostListViewControllerTest : public ::testing::Test { | |
21 protected: | |
22 virtual void SetUp() OVERRIDE { | |
23 controller_ = [[HostListViewController alloc] init]; | |
24 SetHostByCount(1); | |
25 } | |
26 | |
27 void SetHostByCount(int numHosts) { | |
28 NSArray* array = | |
29 [Host parseListFromJSON:HostRefreshTestHelper::GetHostList(numHosts)]; | |
30 RefreshHostList(array); | |
31 } | |
32 | |
33 void SetHostByString(NSString* string) { | |
34 NSArray* array = | |
35 [Host parseListFromJSON:HostRefreshTestHelper::GetHostList(string)]; | |
36 RefreshHostList(array); | |
37 } | |
38 | |
39 void RefreshHostList(NSArray* array) { | |
40 [controller_ hostListRefresh:array errorMessage:nil]; | |
41 } | |
42 | |
43 HostListViewController* controller_; | |
44 }; | |
45 | |
46 TEST_F(HostListViewControllerTest, DefaultAuthorization) { | |
47 ASSERT_TRUE(controller_.authorization == nil); | |
48 | |
49 [controller_ viewWillAppear:YES]; | |
50 | |
51 ASSERT_TRUE(controller_.authorization != nil); | |
52 } | |
53 | |
54 TEST_F(HostListViewControllerTest, hostListRefresh) { | |
55 SetHostByCount(2); | |
56 ASSERT_EQ(2, [controller_ tableView:nil numberOfRowsInSection:0]); | |
57 | |
58 SetHostByCount(10); | |
59 ASSERT_EQ(10, [controller_ tableView:nil numberOfRowsInSection:0]); | |
60 } | |
61 | |
62 TEST_F(HostListViewControllerTest, | |
63 ShouldPerformSegueWithIdentifierOfConnectToHost) { | |
64 ASSERT_FALSE([controller_ shouldPerformSegueWithIdentifier:@"ConnectToHost" | |
65 sender:nil]); | |
66 | |
67 NSString* host = HostRefreshTestHelper::GetMultipleHosts(1); | |
68 host = [host stringByReplacingOccurrencesOfString:@"TESTING" | |
69 withString:@"ONLINE"]; | |
70 SetHostByString(host); | |
71 ASSERT_TRUE([controller_ shouldPerformSegueWithIdentifier:@"ConnectToHost" | |
72 sender:nil]); | |
73 } | |
74 | |
75 TEST_F(HostListViewControllerTest, prepareSegueWithIdentifierOfConnectToHost) { | |
76 HostViewController* destination = [[HostViewController alloc] init]; | |
77 | |
78 ASSERT_NSNE(HostRefreshTestHelper::HostNameTest, destination.host.hostName); | |
79 | |
80 UIStoryboardSegue* seque = | |
81 [[UIStoryboardSegue alloc] initWithIdentifier:@"ConnectToHost" | |
82 source:controller_ | |
83 destination:destination]; | |
84 | |
85 [controller_ prepareForSegue:seque sender:nil]; | |
86 | |
87 ASSERT_NSEQ(HostRefreshTestHelper::HostNameTest, destination.host.hostName); | |
88 } | |
89 | |
90 } // namespace remoting | |
OLD | NEW |