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

Side by Side Diff: content/browser/accessibility/android_granularity_movement_browsertest.cc

Issue 1239493005: Remove some legacy versions of StartsWith and EndsWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 static_cast<BrowserAccessibilityManagerAndroid*>(node->manager()); 84 static_cast<BrowserAccessibilityManagerAndroid*>(node->manager());
85 base::string16 text = android_node->GetText(); 85 base::string16 text = android_node->GetText();
86 base::string16 concatenated; 86 base::string16 concatenated;
87 int previous_end_index = -1; 87 int previous_end_index = -1;
88 while (manager->NextAtGranularity( 88 while (manager->NextAtGranularity(
89 granularity, end_index, android_node, 89 granularity, end_index, android_node,
90 &start_index, &end_index)) { 90 &start_index, &end_index)) {
91 int len = (granularity == GRANULARITY_CHARACTER) ? 91 int len = (granularity == GRANULARITY_CHARACTER) ?
92 1 : end_index - start_index; 92 1 : end_index - start_index;
93 base::string16 selection = text.substr(start_index, len); 93 base::string16 selection = text.substr(start_index, len);
94 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), false)) 94 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"),
95 base::CompareCase::INSENSITIVE_ASCII))
95 selection.erase(selection.size() - 1); 96 selection.erase(selection.size() - 1);
96 if (!selection.empty()) { 97 if (!selection.empty()) {
97 if (!concatenated.empty()) 98 if (!concatenated.empty())
98 concatenated += base::ASCIIToUTF16(", "); 99 concatenated += base::ASCIIToUTF16(", ");
99 concatenated += base::ASCIIToUTF16("'") + selection + 100 concatenated += base::ASCIIToUTF16("'") + selection +
100 base::ASCIIToUTF16("'"); 101 base::ASCIIToUTF16("'");
101 } 102 }
102 103
103 // Prevent an endless loop. 104 // Prevent an endless loop.
104 if (end_index == previous_end_index) { 105 if (end_index == previous_end_index) {
105 LOG(ERROR) << "Bailing from loop, NextAtGranularity didn't advance"; 106 LOG(ERROR) << "Bailing from loop, NextAtGranularity didn't advance";
106 break; 107 break;
107 } 108 }
108 previous_end_index = end_index; 109 previous_end_index = end_index;
109 } 110 }
110 111
111 base::string16 reverse; 112 base::string16 reverse;
112 previous_end_index = -1; 113 previous_end_index = -1;
113 start_index = end_index; 114 start_index = end_index;
114 while (manager->PreviousAtGranularity( 115 while (manager->PreviousAtGranularity(
115 granularity, start_index, android_node, &start_index, &end_index)) { 116 granularity, start_index, android_node, &start_index, &end_index)) {
116 int len = (granularity == GRANULARITY_CHARACTER) ? 117 int len = (granularity == GRANULARITY_CHARACTER) ?
117 1 : end_index - start_index; 118 1 : end_index - start_index;
118 base::string16 selection = text.substr(start_index, len); 119 base::string16 selection = text.substr(start_index, len);
119 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), false)) 120 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"),
121 base::CompareCase::INSENSITIVE_ASCII))
120 selection = selection.substr(0, selection.size() - 1); 122 selection = selection.substr(0, selection.size() - 1);
121 if (!reverse.empty()) 123 if (!reverse.empty())
122 reverse = base::ASCIIToUTF16(", ") + reverse; 124 reverse = base::ASCIIToUTF16(", ") + reverse;
123 reverse = base::ASCIIToUTF16("'") + selection + 125 reverse = base::ASCIIToUTF16("'") + selection +
124 base::ASCIIToUTF16("'") + reverse; 126 base::ASCIIToUTF16("'") + reverse;
125 127
126 // Prevent an endless loop. 128 // Prevent an endless loop.
127 if (end_index == previous_end_index) { 129 if (end_index == previous_end_index) {
128 LOG(ERROR) << "Bailing from loop, PreviousAtGranularity didn't advance"; 130 LOG(ERROR) << "Bailing from loop, PreviousAtGranularity didn't advance";
129 break; 131 break;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 BrowserAccessibility* root = LoadUrlAndGetAccessibilityRoot(url); 202 BrowserAccessibility* root = LoadUrlAndGetAccessibilityRoot(url);
201 ASSERT_EQ(1U, root->PlatformChildCount()); 203 ASSERT_EQ(1U, root->PlatformChildCount());
202 BrowserAccessibility* pre = root->PlatformGetChild(0); 204 BrowserAccessibility* pre = root->PlatformGetChild(0);
203 ASSERT_EQ(0U, pre->PlatformChildCount()); 205 ASSERT_EQ(0U, pre->PlatformChildCount());
204 206
205 ASSERT_EQ(base::ASCIIToUTF16("'One,', 'two,', 'three!'"), 207 ASSERT_EQ(base::ASCIIToUTF16("'One,', 'two,', 'three!'"),
206 TraverseNodeAtGranularity(pre, GRANULARITY_LINE)); 208 TraverseNodeAtGranularity(pre, GRANULARITY_LINE));
207 } 209 }
208 210
209 } // namespace content 211 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698