Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: ios/chrome/browser/ui/util/label_observer_unittest.mm

Issue 2828743002: LabelObserver is no longer retained by the label (Closed)
Patch Set: Address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/util/label_observer.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ios/chrome/browser/ui/util/label_observer.h" 5 #include "ios/chrome/browser/ui/util/label_observer.h"
6 6
7 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/gtest_mac.h" 10 #include "testing/gtest_mac.h"
11 #include "testing/platform_test.h" 11 #include "testing/platform_test.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 13
14 namespace { 14 namespace {
15 15
16 class LabelObserverTest : public PlatformTest { 16 class LabelObserverTest : public PlatformTest {
17 protected: 17 protected:
18 void SetUp() override { 18 void SetUp() override {
19 label_.reset([[UILabel alloc] initWithFrame:CGRectZero]); 19 label_.reset([[UILabel alloc] initWithFrame:CGRectZero]);
20 observer_.reset([[LabelObserver observerForLabel:label_.get()] retain]);
21 [observer_ startObserving];
20 } 22 }
21 23
24 ~LabelObserverTest() override { [observer_ stopObserving]; }
25
22 UILabel* label() { return label_.get(); } 26 UILabel* label() { return label_.get(); }
23 LabelObserver* observer() { return [LabelObserver observerForLabel:label()]; } 27 LabelObserver* observer() { return observer_.get(); }
24 28
25 base::scoped_nsobject<UILabel> label_; 29 base::scoped_nsobject<UILabel> label_;
30 base::scoped_nsobject<LabelObserver> observer_;
26 }; 31 };
27 32
28 // Tests that all types of LabelObserverActions are successfully called. 33 // Tests that all types of LabelObserverActions are successfully called.
29 TEST_F(LabelObserverTest, SimpleTest) { 34 TEST_F(LabelObserverTest, SimpleTest) {
30 __block BOOL text_action_called = NO; 35 __block BOOL text_action_called = NO;
31 [observer() addTextChangedAction:^(UILabel* label) { 36 [observer() addTextChangedAction:^(UILabel* label) {
32 text_action_called = YES; 37 text_action_called = YES;
33 }]; 38 }];
34 label().text = @"text"; 39 label().text = @"text";
35 EXPECT_TRUE(text_action_called); 40 EXPECT_TRUE(text_action_called);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 EXPECT_TRUE(first_action_called); 79 EXPECT_TRUE(first_action_called);
75 EXPECT_FALSE(second_action_called); 80 EXPECT_FALSE(second_action_called);
76 second_action_called = YES; 81 second_action_called = YES;
77 }]; 82 }];
78 label().text = @"test"; 83 label().text = @"test";
79 EXPECT_TRUE(first_action_called); 84 EXPECT_TRUE(first_action_called);
80 EXPECT_TRUE(second_action_called); 85 EXPECT_TRUE(second_action_called);
81 } 86 }
82 87
83 } // namespace 88 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/util/label_observer.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698