AU: Don't send no-op operations in the delta payload.

This reduces the payload a bit and also speeds up updates on the client by
reducing the I/O.

This CL also removes a somewhat broken check for written blocks. It seems that
the intent of the check was to make sure each block is updated with some data
but since some file data blocks may be used as scratch the check is somewhat
meaningless. The CL removes the check because some blocks may never be written
if they were a part of a no-op operation.

BUG=7543
TEST=unit tests, generated a no-op delta an installed on the device

Change-Id: I31f388651a45d10dd931389a6c80ac18cb10f466

Review URL: http://codereview.chromium.org/3785008
diff --git a/delta_performer_unittest.cc b/delta_performer_unittest.cc
index e9d44fa..3c05b1d 100755
--- a/delta_performer_unittest.cc
+++ b/delta_performer_unittest.cc
@@ -9,6 +9,7 @@
 #include <string>
 #include <vector>
 
+#include <base/file_util.h>
 #include <base/scoped_ptr.h>
 #include <base/string_util.h>
 #include <google/protobuf/repeated_field.h>
@@ -112,7 +113,7 @@
   return true;
 }
 
-void DoSmallImageTest(bool full_kernel) {
+void DoSmallImageTest(bool full_kernel, bool noop) {
   string a_img, b_img;
   EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL));
   ScopedPathUnlinker a_img_unlinker(a_img);
@@ -120,7 +121,6 @@
   ScopedPathUnlinker b_img_unlinker(b_img);
 
   CreateExtImageAtPath(a_img, NULL);
-  CreateExtImageAtPath(b_img, NULL);
 
   int image_size = static_cast<int>(utils::FileSize(a_img));
 
@@ -129,12 +129,7 @@
       "dd if=/dev/zero of=%s seek=%d bs=1 count=1",
       a_img.c_str(),
       image_size + 1024 * 1024 - 1)));
-  EXPECT_EQ(0, System(base::StringPrintf(
-      "dd if=/dev/zero of=%s seek=%d bs=1 count=1",
-      b_img.c_str(),
-      image_size + 1024 * 1024 - 1)));
   EXPECT_EQ(image_size + 1024 * 1024, utils::FileSize(a_img));
-  EXPECT_EQ(image_size + 1024 * 1024, utils::FileSize(b_img));
 
   // Make some changes to the A image.
   {
@@ -154,8 +149,17 @@
                                  ones.size()));
   }
 
-  // Make some changes to the B image.
-  {
+  if (noop) {
+    EXPECT_TRUE(file_util::CopyFile(FilePath(a_img), FilePath(b_img)));
+  } else {
+    CreateExtImageAtPath(b_img, NULL);
+    EXPECT_EQ(0, System(base::StringPrintf(
+        "dd if=/dev/zero of=%s seek=%d bs=1 count=1",
+        b_img.c_str(),
+        image_size + 1024 * 1024 - 1)));
+    EXPECT_EQ(image_size + 1024 * 1024, utils::FileSize(b_img));
+
+    // Make some changes to the B image.
     string b_mnt;
     ScopedLoopMounter b_mounter(b_img, &b_mnt, 0);
 
@@ -196,6 +200,10 @@
   const char* new_data_string = "This is new data.";
   strcpy(&new_kernel_data[0], new_data_string);
 
+  if (noop) {
+    old_kernel_data = new_kernel_data;
+  }
+
   // Write kernels to disk
   EXPECT_TRUE(utils::WriteFile(
       old_kernel.c_str(), &old_kernel_data[0], old_kernel_data.size()));
@@ -258,6 +266,11 @@
     EXPECT_EQ(expected_sig_data_length, manifest.signatures_size());
     EXPECT_FALSE(signature.data().empty());
 
+    if (noop) {
+      EXPECT_EQ(1, manifest.install_operations_size());
+      EXPECT_EQ(1, manifest.kernel_install_operations_size());
+    }
+
     if (full_kernel) {
       EXPECT_FALSE(manifest.has_old_kernel_info());
     } else {
@@ -333,11 +346,15 @@
 }
 
 TEST(DeltaPerformerTest, RunAsRootSmallImageTest) {
-  DoSmallImageTest(false);
+  DoSmallImageTest(false, false);
 }
 
 TEST(DeltaPerformerTest, RunAsRootFullKernelSmallImageTest) {
-  DoSmallImageTest(true);
+  DoSmallImageTest(true, false);
+}
+
+TEST(DeltaPerformerTest, RunAsRootNoopSmallImageTest) {
+  DoSmallImageTest(false, true);
 }
 
 TEST(DeltaPerformerTest, NewFullUpdateTest) {