diff --git a/dart/lib/html.dart b/dart/lib/html.dart
index 0082a70a..55147590 100644
--- a/dart/lib/html.dart
+++ b/dart/lib/html.dart
@@ -169,7 +169,7 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {
// TODO(DrMarcII) consider normalizing string
@override
- String get visibleText => _elementText(node).trim();
+ String get visibleText => _normalize(_elementText(node));
@override
List getElementsByCss(String selector) =>
@@ -487,6 +487,32 @@ String _elementText(n) {
return _elementText(n.nodes);
}
+final _nonBreaking = new RegExp(r'^[\S\xa0]$');
+
+String _normalize(String string) {
+ var skipWS = true;
+ var addWS = false;
+ var buffer = new StringBuffer();
+ for (int i = 0; i < string.length; i++) {
+ var char = string[i];
+ if (char.contains(_nonBreaking)) {
+ if (addWS) {
+ buffer.write(' ');
+ }
+ if (char == '\xa0') {
+ buffer.write(' ');
+ } else {
+ buffer.write(char);
+ }
+ skipWS = false;
+ } else if (!skipWS) {
+ addWS = true;
+ skipWS = true;
+ }
+ }
+ return buffer.toString();
+}
+
class _SyncActionClock extends FakeClock {
final SyncActionFn syncActionFn;
diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml
index 4eede9df..d15f2c0e 100644
--- a/dart/pubspec.yaml
+++ b/dart/pubspec.yaml
@@ -1,5 +1,5 @@
name: pageloader
-version: 1.3.1
+version: 1.3.2
author: Google Inc.
description: >
Supports the creation of page objects that can be shared between in-browser tests
diff --git a/dart/test/html_no_shadow_dom_test.dart b/dart/test/html_no_shadow_dom_test.dart
index 103e1330..933462a2 100644
--- a/dart/test/html_no_shadow_dom_test.dart
+++ b/dart/test/html_no_shadow_dom_test.dart
@@ -76,7 +76,8 @@ void main() {
- ''';
+
+
''';
var div = body.querySelectorAll('div[id=testdocument]');
if (div.length == 1) {
diff --git a/dart/test/html_test.dart b/dart/test/html_test.dart
index b5ce9aca..2d49a979 100644
--- a/dart/test/html_test.dart
+++ b/dart/test/html_test.dart
@@ -76,7 +76,8 @@ void main() {
button 2
- ''';
+
+
''';
var templateHtml = '';
diff --git a/dart/test/page_objects.dart b/dart/test/page_objects.dart
index 02596a0e..334ff363 100644
--- a/dart/test/page_objects.dart
+++ b/dart/test/page_objects.dart
@@ -434,3 +434,8 @@ class PageForTextAreaTypingText {
@ById('textarea')
PageLoaderElement textArea;
}
+
+class PageForNbspTest {
+ @ById('nbsp')
+ PageLoaderElement span;
+}
diff --git a/dart/test/pageloader_test.dart b/dart/test/pageloader_test.dart
index 3b3d3d5d..e51db0a8 100644
--- a/dart/test/pageloader_test.dart
+++ b/dart/test/pageloader_test.dart
@@ -372,6 +372,12 @@ void runTests() {
page.textArea.clear();
expect(page.textArea.attributes['value'], '');
});
+
+ solo_test('nbsp in text', () {
+ PageForNbspTest page = loader.getInstance(PageForNbspTest);
+ expect(page.span.visibleText, ' ');
+ expect(page.span.innerText, '');
+ });
});
group('waitFor()', () {
diff --git a/dart/test/webdriver_no_shadow_dom_test_page.html b/dart/test/webdriver_no_shadow_dom_test_page.html
index 3a393a1e..a66245dd 100644
--- a/dart/test/webdriver_no_shadow_dom_test_page.html
+++ b/dart/test/webdriver_no_shadow_dom_test_page.html
@@ -70,5 +70,7 @@
+
+