Fix API change of findInPage API
authorCheng Zhao <zcbenz@gmail.com>
Thu, 8 Sep 2016 05:27:10 +0000 (14:27 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 14 Sep 2016 07:23:00 +0000 (16:23 +0900)
atom/browser/api/atom_api_web_contents.cc
spec/webview-spec.js

index 467131a..816fc00 100644 (file)
@@ -532,18 +532,12 @@ void WebContents::FindReply(content::WebContents* web_contents,
   v8::HandleScope handle_scope(isolate());
 
   mate::Dictionary result = mate::Dictionary::CreateEmpty(isolate());
-  if (number_of_matches == -1) {
-    result.Set("requestId", request_id);
-    result.Set("selectionArea", selection_rect);
-    result.Set("finalUpdate", final_update);
-    result.Set("activeMatchOrdinal", active_match_ordinal);
-    Emit("found-in-page", result);
-  } else if (final_update) {
-    result.Set("requestId", request_id);
-    result.Set("matches", number_of_matches);
-    result.Set("finalUpdate", final_update);
-    Emit("found-in-page", result);
-  }
+  result.Set("requestId", request_id);
+  result.Set("matches", number_of_matches);
+  result.Set("finalUpdate", final_update);
+  result.Set("selectionArea", selection_rect);
+  result.Set("activeMatchOrdinal", active_match_ordinal);
+  Emit("found-in-page", result);
 }
 
 bool WebContents::CheckMediaAccessPermission(
index 6b36c84..01374ba 100644 (file)
@@ -780,25 +780,21 @@ describe('<webview> tag', function () {
 
   describe('found-in-page event', function () {
     it('emits when a request is made', function (done) {
-      var requestId = null
-      var totalMatches = null
-      var activeMatchOrdinal = []
-      var listener = function (e) {
+      let requestId = null
+      let activeMatchOrdinal = []
+      const listener = function (e) {
         assert.equal(e.result.requestId, requestId)
-        if (e.result.finalUpdate) {
-          assert.equal(e.result.matches, 3)
-          totalMatches = e.result.matches
-          listener2()
+        assert.equal(e.result.matches, 3)
+        activeMatchOrdinal.push(e.result.activeMatchOrdinal)
+        if (e.result.activeMatchOrdinal === e.result.matches) {
+          assert.deepEqual(activeMatchOrdinal, [1, 2, 3])
+          webview.stopFindInPage('clearSelection')
+          done()
         } else {
-          activeMatchOrdinal.push(e.result.activeMatchOrdinal)
-          if (e.result.activeMatchOrdinal === totalMatches) {
-            assert.deepEqual(activeMatchOrdinal, [1, 2, 3])
-            webview.stopFindInPage('clearSelection')
-            done()
-          }
+          listener2()
         }
       }
-      var listener2 = function () {
+      const listener2 = function () {
         requestId = webview.findInPage('virtual')
       }
       webview.addEventListener('found-in-page', listener)