Merge "Fix NPEs after merge of d159ec534823b87f9896843e95912b0df8c27e16 from open source master."
diff --git a/res/drawable-mdpi/ic_btn_copy.png b/res/drawable-mdpi/ic_btn_copy.png
new file mode 100644
index 0000000..04fda7f
--- /dev/null
+++ b/res/drawable-mdpi/ic_btn_copy.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_btn_find.png b/res/drawable-mdpi/ic_btn_find.png
new file mode 100755
index 0000000..20e1fbc
--- /dev/null
+++ b/res/drawable-mdpi/ic_btn_find.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_btn_select_all.png b/res/drawable-mdpi/ic_btn_select_all.png
new file mode 100644
index 0000000..839915b
--- /dev/null
+++ b/res/drawable-mdpi/ic_btn_select_all.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_btn_share.png b/res/drawable-mdpi/ic_btn_share.png
new file mode 100644
index 0000000..44db9b1
--- /dev/null
+++ b/res/drawable-mdpi/ic_btn_share.png
Binary files differ
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index a313651..ebbb055 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -1041,12 +1041,12 @@
         }
 
         @Override
-        public void onSelectionDone() {
+        public void onSelectionDone(WebView view) {
             if (mInForeground) mActivity.closeDialogs();
         }
 
         @Override
-        public void onSelectionStart() {
+        public void onSelectionStart(WebView view) {
             if (mInForeground) mActivity.showSelectDialog();
         }
 
diff --git a/tests/src/com/android/browser/PopularUrlsTest.java b/tests/src/com/android/browser/PopularUrlsTest.java
index 5b8cb86..b1760e9 100644
--- a/tests/src/com/android/browser/PopularUrlsTest.java
+++ b/tests/src/com/android/browser/PopularUrlsTest.java
@@ -63,6 +63,7 @@
     private Instrumentation mInst = null;
     private CountDownLatch mLatch = new CountDownLatch(1);
     private RunStatus mStatus;
+    private boolean pageLoadFinishCalled, pageProgressFull;
 
     public PopularUrlsTest() {
         super(BrowserActivity.class);
@@ -72,6 +73,8 @@
     protected void setUp() throws Exception {
         super.setUp();
 
+        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("about:blank"));
+        setActivityIntent(i);
         mActivity = getActivity();
         mInst = getInstrumentation();
         mInst.waitForIdleSync();
@@ -122,14 +125,18 @@
 
         webView.setWebChromeClient(new TestWebChromeClient(webView.getWebChromeClient()) {
 
-            /**
-             * Reset the latch whenever page progress reaches 100%.
-             */
             @Override
             public void onProgressChanged(WebView view, int newProgress) {
                 super.onProgressChanged(view, newProgress);
                 if (newProgress >= 100) {
-                    resetLatch();
+                    if (!pageProgressFull) {
+                        // void duplicate calls
+                        pageProgressFull  = true;
+                        if (pageLoadFinishCalled) {
+                            //reset latch and move forward only if both indicators are true
+                            resetLatch();
+                        }
+                    }
                 }
             }
 
@@ -206,20 +213,38 @@
                     String host, String realm) {
                 handler.proceed("user", "passwd");
             }
+
+            /* (non-Javadoc)
+             * @see com.android.browser.TestWebViewClient#onPageFinished(android.webkit.WebView, java.lang.String)
+             */
+            @Override
+            public void onPageFinished(WebView view, String url) {
+                if (!pageLoadFinishCalled) {
+                    pageLoadFinishCalled = true;
+                    if (pageProgressFull) {
+                        //reset latch and move forward only if both indicators are true
+                        resetLatch();
+                    }
+                }
+            }
+
         });
     }
 
     void resetLatch() {
-        CountDownLatch temp = mLatch;
-        mLatch = new CountDownLatch(1);
-        if (temp != null) {
-            // Notify existing latch that it's done.
-            while (temp.getCount() > 0) {
-                temp.countDown();
-            }
+        if (mLatch.getCount() != 1) {
+            Log.w(TAG, "Expecting latch to be 1, but it's not!");
+        } else {
+            mLatch.countDown();
         }
     }
 
+    void resetForNewPage() {
+        mLatch = new CountDownLatch(1);
+        pageLoadFinishCalled = false;
+        pageProgressFull = false;
+    }
+
     void waitForLoad() throws InterruptedException {
         boolean timedout = !mLatch.await(PAGE_LOAD_TIMEOUT, TimeUnit.MILLISECONDS);
         if (timedout) {
@@ -372,18 +397,19 @@
         }
 
         while (mStatus.getIteration() < loopCount) {
+            if (clearCache) {
+                webView.clearCache(true);
+            }
             while(iterator.hasNext()) {
                 page = iterator.next();
                 mStatus.setUrl(page);
                 mStatus.write();
                 Log.i(TAG, "start: " + page);
                 Uri uri = Uri.parse(page);
-                if (clearCache) {
-                    webView.clearCache(true);
-                }
                 final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
 
                 long startTime = System.currentTimeMillis();
+                resetForNewPage();
                 mInst.runOnMainSync(new Runnable() {
 
                     public void run() {