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 1233453011: Revert of Remove some legacy versions of StartsWith and EndsWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « components/wifi/wifi_service_win.cc ('k') | content/browser/plugin_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"), 94 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), false))
95 base::CompareCase::INSENSITIVE_ASCII))
96 selection.erase(selection.size() - 1); 95 selection.erase(selection.size() - 1);
97 if (!selection.empty()) { 96 if (!selection.empty()) {
98 if (!concatenated.empty()) 97 if (!concatenated.empty())
99 concatenated += base::ASCIIToUTF16(", "); 98 concatenated += base::ASCIIToUTF16(", ");
100 concatenated += base::ASCIIToUTF16("'") + selection + 99 concatenated += base::ASCIIToUTF16("'") + selection +
101 base::ASCIIToUTF16("'"); 100 base::ASCIIToUTF16("'");
102 } 101 }
103 102
104 // Prevent an endless loop. 103 // Prevent an endless loop.
105 if (end_index == previous_end_index) { 104 if (end_index == previous_end_index) {
106 LOG(ERROR) << "Bailing from loop, NextAtGranularity didn't advance"; 105 LOG(ERROR) << "Bailing from loop, NextAtGranularity didn't advance";
107 break; 106 break;
108 } 107 }
109 previous_end_index = end_index; 108 previous_end_index = end_index;
110 } 109 }
111 110
112 base::string16 reverse; 111 base::string16 reverse;
113 previous_end_index = -1; 112 previous_end_index = -1;
114 start_index = end_index; 113 start_index = end_index;
115 while (manager->PreviousAtGranularity( 114 while (manager->PreviousAtGranularity(
116 granularity, start_index, android_node, &start_index, &end_index)) { 115 granularity, start_index, android_node, &start_index, &end_index)) {
117 int len = (granularity == GRANULARITY_CHARACTER) ? 116 int len = (granularity == GRANULARITY_CHARACTER) ?
118 1 : end_index - start_index; 117 1 : end_index - start_index;
119 base::string16 selection = text.substr(start_index, len); 118 base::string16 selection = text.substr(start_index, len);
120 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), 119 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), false))
121 base::CompareCase::INSENSITIVE_ASCII))
122 selection = selection.substr(0, selection.size() - 1); 120 selection = selection.substr(0, selection.size() - 1);
123 if (!reverse.empty()) 121 if (!reverse.empty())
124 reverse = base::ASCIIToUTF16(", ") + reverse; 122 reverse = base::ASCIIToUTF16(", ") + reverse;
125 reverse = base::ASCIIToUTF16("'") + selection + 123 reverse = base::ASCIIToUTF16("'") + selection +
126 base::ASCIIToUTF16("'") + reverse; 124 base::ASCIIToUTF16("'") + reverse;
127 125
128 // Prevent an endless loop. 126 // Prevent an endless loop.
129 if (end_index == previous_end_index) { 127 if (end_index == previous_end_index) {
130 LOG(ERROR) << "Bailing from loop, PreviousAtGranularity didn't advance"; 128 LOG(ERROR) << "Bailing from loop, PreviousAtGranularity didn't advance";
131 break; 129 break;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 BrowserAccessibility* root = LoadUrlAndGetAccessibilityRoot(url); 200 BrowserAccessibility* root = LoadUrlAndGetAccessibilityRoot(url);
203 ASSERT_EQ(1U, root->PlatformChildCount()); 201 ASSERT_EQ(1U, root->PlatformChildCount());
204 BrowserAccessibility* pre = root->PlatformGetChild(0); 202 BrowserAccessibility* pre = root->PlatformGetChild(0);
205 ASSERT_EQ(0U, pre->PlatformChildCount()); 203 ASSERT_EQ(0U, pre->PlatformChildCount());
206 204
207 ASSERT_EQ(base::ASCIIToUTF16("'One,', 'two,', 'three!'"), 205 ASSERT_EQ(base::ASCIIToUTF16("'One,', 'two,', 'three!'"),
208 TraverseNodeAtGranularity(pre, GRANULARITY_LINE)); 206 TraverseNodeAtGranularity(pre, GRANULARITY_LINE));
209 } 207 }
210 208
211 } // namespace content 209 } // namespace content
OLDNEW
« no previous file with comments | « components/wifi/wifi_service_win.cc ('k') | content/browser/plugin_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698